From 5d6559e83900c0518dc47a0d7b775355dcd8c1e8 Mon Sep 17 00:00:00 2001 From: martyfuhry Date: Thu, 2 Feb 2023 13:20:26 -0500 Subject: [PATCH] fix(mobile): back button while multiselecting showing the last selected image (#1521) --- .../home/ui/asset_grid/immich_asset_grid.dart | 25 +++++-- mobile/lib/modules/home/views/home_page.dart | 68 ++++++++----------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart b/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart index d0f82990b8..a6a08aadda 100644 --- a/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart +++ b/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart @@ -224,13 +224,28 @@ class ImmichAssetGridState extends State { } } + + Future onWillPop() async { + if (widget.selectionActive && _selectedAssets.isNotEmpty) { + _deselectAll(); + return false; + } + + return true; + } + + + @override Widget build(BuildContext context) { - return Stack( - children: [ - _buildAssetGrid(), - if (widget.selectionActive) _buildMultiSelectIndicator(), - ], + return WillPopScope( + onWillPop: onWillPop, + child: Stack( + children: [ + _buildAssetGrid(), + if (widget.selectionActive) _buildMultiSelectIndicator(), + ], + ), ); } } diff --git a/mobile/lib/modules/home/views/home_page.dart b/mobile/lib/modules/home/views/home_page.dart index 5b1ac7cd14..d032a61651 100644 --- a/mobile/lib/modules/home/views/home_page.dart +++ b/mobile/lib/modules/home/views/home_page.dart @@ -200,46 +200,34 @@ class HomePage extends HookConsumerWidget { ); } - Future onWillPop() async { - if (multiselectEnabled.state) { - selectionEnabledHook.value = false; - return false; - } - - return true; - } - - return WillPopScope( - onWillPop: onWillPop, - child: SafeArea( - bottom: !multiselectEnabled.state, - top: true, - child: Stack( - children: [ - ref.watch(assetProvider).renderList == null || - ref.watch(assetProvider).allAssets.isEmpty - ? buildLoadingIndicator() - : ImmichAssetGrid( - renderList: ref.watch(assetProvider).renderList!, - allAssets: ref.watch(assetProvider).allAssets, - assetsPerRow: appSettingService - .getSetting(AppSettingsEnum.tilesPerRow), - showStorageIndicator: appSettingService - .getSetting(AppSettingsEnum.storageIndicator), - listener: selectionListener, - selectionActive: selectionEnabledHook.value, - ), - if (selectionEnabledHook.value) - ControlBottomAppBar( - onShare: onShareAssets, - onDelete: onDelete, - onAddToAlbum: onAddToAlbum, - albums: albums, - sharedAlbums: sharedAlbums, - onCreateNewAlbum: onCreateNewAlbum, - ), - ], - ), + return SafeArea( + bottom: !multiselectEnabled.state, + top: true, + child: Stack( + children: [ + ref.watch(assetProvider).renderList == null || + ref.watch(assetProvider).allAssets.isEmpty + ? buildLoadingIndicator() + : ImmichAssetGrid( + renderList: ref.watch(assetProvider).renderList!, + allAssets: ref.watch(assetProvider).allAssets, + assetsPerRow: appSettingService + .getSetting(AppSettingsEnum.tilesPerRow), + showStorageIndicator: appSettingService + .getSetting(AppSettingsEnum.storageIndicator), + listener: selectionListener, + selectionActive: selectionEnabledHook.value, + ), + if (selectionEnabledHook.value) + ControlBottomAppBar( + onShare: onShareAssets, + onDelete: onDelete, + onAddToAlbum: onAddToAlbum, + albums: albums, + sharedAlbums: sharedAlbums, + onCreateNewAlbum: onCreateNewAlbum, + ), + ], ), ); }