mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-13 18:58:53 +01:00
Fix broken double tab to exit in new Photos and Collections tab
This commit is contained in:
parent
dccbad2185
commit
65a1a02926
2 changed files with 41 additions and 3 deletions
|
@ -33,6 +33,7 @@ import 'package:nc_photos/widget/archive_browser.dart';
|
|||
import 'package:nc_photos/widget/collection_browser.dart';
|
||||
import 'package:nc_photos/widget/collection_grid_item.dart';
|
||||
import 'package:nc_photos/widget/enhanced_photo_browser.dart';
|
||||
import 'package:nc_photos/widget/handler/double_tap_exit_handler.dart';
|
||||
import 'package:nc_photos/widget/home_app_bar.dart';
|
||||
import 'package:nc_photos/widget/navigation_bar_blur_filter.dart';
|
||||
import 'package:nc_photos/widget/new_collection_dialog.dart';
|
||||
|
@ -42,6 +43,7 @@ import 'package:nc_photos/widget/selection_app_bar.dart';
|
|||
import 'package:nc_photos/widget/sharing_browser.dart';
|
||||
import 'package:nc_photos/widget/trashbin_browser.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
@ -89,7 +91,7 @@ class _WrappedHomeCollectionsState extends State<_WrappedHomeCollections>
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocListener(
|
||||
final content = MultiBlocListener(
|
||||
listeners: [
|
||||
_BlocListener(
|
||||
listenWhen: (previous, current) =>
|
||||
|
@ -235,6 +237,14 @@ class _WrappedHomeCollectionsState extends State<_WrappedHomeCollections>
|
|||
],
|
||||
),
|
||||
);
|
||||
if (getRawPlatform() == NpPlatform.android) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => _onBackButtonPressed(context),
|
||||
child: content,
|
||||
);
|
||||
} else {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onNewCollectionPressed(BuildContext context) async {
|
||||
|
@ -267,6 +277,15 @@ class _WrappedHomeCollectionsState extends State<_WrappedHomeCollections>
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _onBackButtonPressed(BuildContext context) async {
|
||||
if (context.state.selectedItems.isEmpty) {
|
||||
return DoubleTapExitHandler()();
|
||||
} else {
|
||||
context.addEvent(const _SetSelectedItems(items: {}));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
late final _Bloc _bloc = context.read();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import 'package:nc_photos/widget/collection_browser.dart';
|
|||
import 'package:nc_photos/widget/collection_picker.dart';
|
||||
import 'package:nc_photos/widget/file_sharer_dialog.dart';
|
||||
import 'package:nc_photos/widget/finger_listener.dart';
|
||||
import 'package:nc_photos/widget/handler/double_tap_exit_handler.dart';
|
||||
import 'package:nc_photos/widget/home_app_bar.dart';
|
||||
import 'package:nc_photos/widget/navigation_bar_blur_filter.dart';
|
||||
import 'package:nc_photos/widget/network_thumbnail.dart';
|
||||
|
@ -59,6 +60,7 @@ import 'package:np_common/object_util.dart';
|
|||
import 'package:np_common/or_null.dart';
|
||||
import 'package:np_datetime/np_datetime.dart';
|
||||
import 'package:np_db/np_db.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
import 'package:visibility_detector/visibility_detector.dart';
|
||||
|
@ -115,7 +117,7 @@ class _WrappedHomePhotosState extends State<_WrappedHomePhotos> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return VisibilityDetector(
|
||||
final content = VisibilityDetector(
|
||||
key: _key,
|
||||
onVisibilityChanged: (info) {
|
||||
final isVisible = info.visibleFraction >= 0.2;
|
||||
|
@ -167,6 +169,23 @@ class _WrappedHomePhotosState extends State<_WrappedHomePhotos> {
|
|||
),
|
||||
),
|
||||
);
|
||||
if (getRawPlatform() == NpPlatform.android) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => _onBackButtonPressed(context),
|
||||
child: content,
|
||||
);
|
||||
} else {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _onBackButtonPressed(BuildContext context) async {
|
||||
if (context.state.selectedItems.isEmpty) {
|
||||
return DoubleTapExitHandler()();
|
||||
} else {
|
||||
context.addEvent(const _SetSelectedItems(items: {}));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
late final _bloc = context.bloc;
|
||||
|
@ -473,7 +492,7 @@ typedef _BlocSelector<T> = BlocSelector<_Bloc, _State, T>;
|
|||
|
||||
extension on BuildContext {
|
||||
_Bloc get bloc => read<_Bloc>();
|
||||
// _State get state => bloc.state;
|
||||
_State get state => bloc.state;
|
||||
void addEvent(_Event event) => bloc.add(event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue