π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Collapse selection actions during swipe scrolling
r4khulc057cc266631
diff --git a/mobile/apps/photos/changes/action-sheet-polish.md b/mobile/apps/photos/changes/action-sheet-polish.mdindex cae7cfc885..7f62b44cea 100644--- a/mobile/apps/photos/changes/action-sheet-polish.md+++ b/mobile/apps/photos/changes/action-sheet-polish.md@@ -1 +1,2 @@- Improved action sheet legibility with consistent icons and text.+- Made selection actions respond faster and collapse reliably while browsing.diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dartindex 0099d908be..d1bf4e2288 100644--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dart+++ b/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dart@@ -3,6 +3,7 @@ import "dart:math" as math;import "package:ente_components/ente_components.dart";import "package:ente_strings/ente_strings.dart";+import "package:flutter/foundation.dart" show ValueListenable;import "package:flutter/material.dart";import "package:flutter/rendering.dart" show ScrollDirection;import "package:hugeicons/hugeicons.dart";@@ -51,6 +52,7 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {InheritedGalleryBoundaries? _boundaries;ScrollController? _galleryController;ValueNotifier<bool>? _galleryScrolling;+ ValueListenable<bool>? _gallerySwipeActive;ScrollController? _actionsController;double? _minHeight;double _minExtent = 0;@@ -74,20 +76,29 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {void _bindGallery() {_galleryController?.removeListener(_onGalleryScroll);_galleryScrolling?.removeListener(_onGalleryActivityChanged);+ _gallerySwipeActive?.removeListener(_onGalleryActivityChanged);_galleryController = _boundaries?.scrollControllerNotifier.value;_galleryController?.addListener(_onGalleryScroll);_galleryScrolling = _galleryController?.positions.length == 1? _galleryController!.position.isScrollingNotifier: null;_galleryScrolling?.addListener(_onGalleryActivityChanged);+ _gallerySwipeActive = _boundaries?.swipeActiveNotifier;+ _gallerySwipeActive?.addListener(_onGalleryActivityChanged);+ _isCollapsing = false;}void _onGalleryScroll() {+ if (_galleryController?.positions.length != 1) return;+ if (_galleryScrolling != _galleryController!.position.isScrollingNotifier ||+ _gallerySwipeActive != _boundaries?.swipeActiveNotifier) {+ _bindGallery();+ }if (_isCollapsing ||!_sheetController.isAttached ||- _galleryController?.positions.length != 1 ||- _galleryController!.position.userScrollDirection ==- ScrollDirection.idle ||+ (_galleryController!.position.userScrollDirection ==+ ScrollDirection.idle &&+ !(_gallerySwipeActive?.value ?? false)) ||_sheetController.size <= _minExtent + 0.001) {return;}@@ -96,7 +107,10 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {}void _onGalleryActivityChanged() {- if (!(_galleryScrolling?.value ?? false)) _isCollapsing = false;+ if (!(_galleryScrolling?.value ?? false) &&+ !(_gallerySwipeActive?.value ?? false)) {+ _isCollapsing = false;+ }}void _toggleSheet() {@@ -143,6 +157,7 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {_boundaries?.scrollControllerNotifier.removeListener(_bindGallery);_galleryController?.removeListener(_onGalleryScroll);_galleryScrolling?.removeListener(_onGalleryActivityChanged);+ _gallerySwipeActive?.removeListener(_onGalleryActivityChanged);_sheetController.dispose();super.dispose();}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex f4ce0d4d7d..09ff137d78 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -824,7 +824,10 @@ class GalleryState extends State<Gallery> {WidgetsBinding.instance.addPostFrameCallback((_) {if (mounted) {- _boundariesProvider?.setScrollController(_scrollController);+ _boundariesProvider?.setScrollController(+ _scrollController,+ swipeActiveNotifier: _swipeActiveNotifier,+ );}});diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dartindex fbba17d746..81c13cc9ab 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_boundaries_provider.dart@@ -1,3 +1,4 @@+import 'package:flutter/foundation.dart' show ValueListenable;import 'package:flutter/material.dart';class GalleryBoundariesProvider extends StatefulWidget {@@ -25,6 +26,7 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {late final ValueNotifier<double?> selectionSheetMinHeightNotifier;late final ValueNotifier<ScrollController?> scrollControllerNotifier;+ ValueListenable<bool>? swipeActiveNotifier;@overridevoid initState() {@@ -44,7 +46,11 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {super.dispose();}- void setScrollController(ScrollController? controller) {+ void setScrollController(+ ScrollController? controller, {+ ValueListenable<bool>? swipeActiveNotifier,+ }) {+ this.swipeActiveNotifier = swipeActiveNotifier;scrollControllerNotifier.value = controller;}@@ -86,8 +92,16 @@ class InheritedGalleryBoundaries extends InheritedWidget {ValueNotifier<ScrollController?> get scrollControllerNotifier =>state.scrollControllerNotifier;- void setScrollController(ScrollController? controller) {- state.setScrollController(controller);+ ValueListenable<bool>? get swipeActiveNotifier => state.swipeActiveNotifier;++ void setScrollController(+ ScrollController? controller, {+ ValueListenable<bool>? swipeActiveNotifier,+ }) {+ state.setScrollController(+ controller,+ swipeActiveNotifier: swipeActiveNotifier,+ );}void setTopBoundary(double? boundary) {diff --git a/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dartindex 7f31e969aa..674e2fab5a 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dart@@ -12,9 +12,23 @@ void main() {tester,) async {final gallery = ScrollController();+ final swipeActive = ValueNotifier(false);addTearDown(gallery.dispose);+ addTearDown(swipeActive.dispose);var tapped = "";- await _pumpSheet(tester, gallery, onTap: (label) => tapped = label);+ await _pumpSheet(+ tester,+ gallery,+ galleryVisible: false,+ swipeActive: swipeActive,+ onTap: (label) => tapped = label,+ );+ await _pumpSheet(+ tester,+ gallery,+ swipeActive: swipeActive,+ onTap: (label) => tapped = label,+ );final sheet = tester.widget<DraggableScrollableSheet>(find.byType(DraggableScrollableSheet),);@@ -36,6 +50,19 @@ void main() {expect(controller.size, sheet.maxChildSize);await tester.tap(find.text("Guest view"));expect(tapped, "Guest view");+ swipeActive.value = true;+ gallery.jumpTo(gallery.offset + 50);+ await tester.pumpAndSettle();+ expect(controller.size, sheet.minChildSize);+ swipeActive.value = false;+ await tester.tap(find.bySemanticsLabel("More"));+ await tester.pumpAndSettle();+ await tester.dragFrom(const Offset(180, 100), const Offset(0, -60));+ await tester.pumpAndSettle();+ expect(controller.size, sheet.minChildSize);+ await tester.tap(find.bySemanticsLabel("More"));+ await tester.pumpAndSettle();+ expect(controller.size, sheet.maxChildSize);final galleryOffset = gallery.offset;await tester.drag(find.byType(CustomScrollView), const Offset(0, 330));await tester.pumpAndSettle();@@ -181,6 +208,8 @@ Future<void> _pumpSheet(Size size = const Size(375, 667),EdgeInsets padding = EdgeInsets.zero,double textScale = 1,+ bool galleryVisible = true,+ ValueNotifier<bool>? swipeActive,bool reduceMotion = false,bool dark = false,List<SelectionSheetAction>? actions,@@ -223,19 +252,22 @@ Future<void> _pumpSheet(child: Builder(builder: (context) {WidgetsBinding.instance.addPostFrameCallback(- (_) => GalleryBoundariesProvider.of(- context,- )!.setScrollController(gallery),+ (_) =>+ GalleryBoundariesProvider.of(context)!.setScrollController(+ gallery,+ swipeActiveNotifier: swipeActive,+ ),);return Stack(alignment: Alignment.bottomCenter,children: [- ListView(- controller: gallery,- children: [- Container(height: 2000, color: Colors.transparent),- ],- ),+ if (galleryVisible)+ ListView(+ controller: gallery,+ children: [+ Container(height: 2000, color: Colors.transparent),+ ],+ ),SelectionActionSheet(selectionControls: Padding(padding: const EdgeInsets.symmetric(horizontal: 8),