Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Stabilize selection sheet gallery padding

r4khulc7d6aa494094
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.dart
index 801846d7a5..8a73e90fe9 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
@@ -52,6 +52,7 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {
ScrollController? _galleryController;
ValueNotifier<bool>? _galleryScrolling;
ScrollController? _actionsController;
+ double? _minHeight;
double _minExtent = 0;
double _maxExtent = 1;
bool _isCollapsing = false;
@@ -123,6 +124,20 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {
}
}
+ void _reportMinHeight(double? height) {
+ _minHeight = height;
+ final boundaries = _boundaries;
+ if (boundaries == null ||
+ boundaries.selectionSheetMinHeightNotifier.value == height) {
+ return;
+ }
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted && _boundaries == boundaries) {
+ boundaries.setSelectionSheetMinHeight(_minHeight);
+ }
+ });
+ }
+
@override
void dispose() {
_boundaries?.scrollControllerNotifier.removeListener(_bindGallery);
@@ -142,7 +157,10 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {
..sort((a, b) => a.gridOrder!.compareTo(b.gridOrder!));
final grid = preferred.isEmpty ? visible.take(4).toList() : preferred;
final rows = visible.where((action) => !grid.contains(action)).toList();
- if (visible.isEmpty) return const SizedBox.shrink();
+ if (visible.isEmpty) {
+ _reportMinHeight(null);
+ return const SizedBox.shrink();
+ }
final media = MediaQuery.of(context);
final isLandscape = media.orientation == Orientation.landscape;
final handlePadding = EdgeInsets.only(
@@ -234,6 +252,7 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {
),
);
if (maxHeight <= controlsHeight + controlsSpacing) {
+ _reportMinHeight(null);
return const SizedBox.shrink();
}
final minHeight = math.min(
@@ -246,6 +265,7 @@ class _SelectionActionSheetState extends State<SelectionActionSheet> {
(rows.isEmpty ? Spacing.sm : dividerHeight + rowHeight / 2),
maxHeight,
);
+ _reportMinHeight(minHeight);
_minExtent = minHeight / availableHeight;
_maxExtent = maxHeight / availableHeight;
final peekExtent = peekHeight / availableHeight;
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 79c075a004..f4ce0d4d7d 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -370,14 +370,15 @@ class GalleryState extends State<Gallery> {
_inheritedSearchFilterData = InheritedSearchFilterData.maybeOf(context);
final boundaries = GalleryBoundariesProvider.of(context);
if (_boundariesProvider != boundaries) {
- _boundariesProvider?.bottomBoundaryNotifier.removeListener(
+ _boundariesProvider?.selectionSheetMinHeightNotifier.removeListener(
_selectedFilesListener,
);
_boundariesProvider = boundaries;
- _boundariesProvider?.bottomBoundaryNotifier.addListener(
+ _boundariesProvider?.selectionSheetMinHeightNotifier.addListener(
_selectedFilesListener,
);
}
+ _selectedFilesListener();
}
void _updateGalleryGroups({bool callSetState = true}) {
@@ -496,14 +497,11 @@ class GalleryState extends State<Gallery> {
void _selectedFilesListener() {
final bottomInset = MediaQuery.paddingOf(context).bottom;
final extra = widget.galleryType == GalleryType.homepage ? 76.0 : 0.0;
- final bottomBoundary = _boundariesProvider?.bottomBoundaryNotifier.value;
+ final minHeight =
+ _boundariesProvider?.selectionSheetMinHeightNotifier.value;
scrollbarBottomPaddingNotifier.value =
- (widget.selectedFiles?.files.isNotEmpty ?? false) &&
- bottomBoundary != null
- ? (MediaQuery.sizeOf(context).height - bottomBoundary).clamp(
- 0.0,
- double.infinity,
- )
+ (widget.selectedFiles?.files.isNotEmpty ?? false) && minHeight != null
+ ? minHeight
: bottomInset + extra;
}
@@ -742,7 +740,7 @@ class GalleryState extends State<Gallery> {
@override
void dispose() {
- _boundariesProvider?.bottomBoundaryNotifier.removeListener(
+ _boundariesProvider?.selectionSheetMinHeightNotifier.removeListener(
_selectedFilesListener,
);
if (_boundariesProvider?.scrollControllerNotifier.value ==
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.dart
index cd06eb004b..fbba17d746 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
@@ -22,6 +22,8 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
// Top edge of the bottom fixed widget.
late final ValueNotifier<double?> bottomBoundaryNotifier;
+ late final ValueNotifier<double?> selectionSheetMinHeightNotifier;
+
late final ValueNotifier<ScrollController?> scrollControllerNotifier;
@override
@@ -29,6 +31,7 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
super.initState();
topBoundaryNotifier = ValueNotifier<double?>(null);
bottomBoundaryNotifier = ValueNotifier<double?>(null);
+ selectionSheetMinHeightNotifier = ValueNotifier<double?>(null);
scrollControllerNotifier = ValueNotifier<ScrollController?>(null);
}
@@ -36,6 +39,7 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
void dispose() {
topBoundaryNotifier.dispose();
bottomBoundaryNotifier.dispose();
+ selectionSheetMinHeightNotifier.dispose();
scrollControllerNotifier.dispose();
super.dispose();
}
@@ -52,6 +56,10 @@ class GalleryBoundariesProviderState extends State<GalleryBoundariesProvider> {
bottomBoundaryNotifier.value = boundary;
}
+ void setSelectionSheetMinHeight(double? height) {
+ selectionSheetMinHeightNotifier.value = height;
+ }
+
@override
Widget build(BuildContext context) {
return InheritedGalleryBoundaries(state: this, child: widget.child);
@@ -72,6 +80,9 @@ class InheritedGalleryBoundaries extends InheritedWidget {
ValueNotifier<double?> get bottomBoundaryNotifier =>
state.bottomBoundaryNotifier;
+ ValueNotifier<double?> get selectionSheetMinHeightNotifier =>
+ state.selectionSheetMinHeightNotifier;
+
ValueNotifier<ScrollController?> get scrollControllerNotifier =>
state.scrollControllerNotifier;
@@ -87,6 +98,10 @@ class InheritedGalleryBoundaries extends InheritedWidget {
state.setBottomBoundary(boundary);
}
+ void setSelectionSheetMinHeight(double? height) {
+ state.setSelectionSheetMinHeight(height);
+ }
+
@override
bool updateShouldNotify(InheritedGalleryBoundaries oldWidget) {
return false;
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
index e92bc3828c..733fded579 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart
@@ -35,7 +35,9 @@ import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";
import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/ui/viewer/gallery/component/album_cover_app_bar.dart";
+import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";
+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
import "package:shared_preferences/shared_preferences.dart";
@@ -174,12 +176,49 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(AlbumCoverActionButton), findsNothing);
expect(find.byTooltip("Sort"), findsNothing);
+ final boundaries = tester.state<GalleryBoundariesProviderState>(
+ find.byType(GalleryBoundariesProvider),
+ );
+ final gallery = tester.state<GalleryState>(find.byType(Gallery));
+ final padding = gallery.scrollbarBottomPaddingNotifier;
+ final minHeight = boundaries.selectionSheetMinHeightNotifier.value!;
+ expect(padding.value, minHeight);
+ final position = boundaries.scrollControllerNotifier.value!.position;
+ final scrollExtent = position.maxScrollExtent;
+ final sheetToggle = find.descendant(
+ of: find.byType(DraggableScrollableSheet),
+ matching: find.bySemanticsLabel("More"),
+ );
+ var paddingUpdates = 0;
+ void trackPadding() => paddingUpdates++;
+ padding.addListener(trackPadding);
+ await tester.tap(sheetToggle);
+ await tester.pumpAndSettle();
+ await tester.pump(const Duration(milliseconds: 100));
+ final expandedBoundary = boundaries.bottomBoundaryNotifier.value!;
+ expect(padding.value, minHeight);
+ expect(position.maxScrollExtent, scrollExtent);
+ await tester.tap(sheetToggle);
+ await tester.pumpAndSettle();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(
+ boundaries.bottomBoundaryNotifier.value!,
+ greaterThan(expandedBoundary),
+ );
+ expect(paddingUpdates, 0);
+ expect(padding.value, minHeight);
+ expect(position.maxScrollExtent, scrollExtent);
+ padding.removeListener(trackPadding);
await tester.tap(find.byType(SelectAllButton));
await tester.pumpAndSettle();
expect(selectedFiles.files, containsAll([oldest, newest]));
await tester.tap(find.byType(ActionBarWidget));
await tester.pumpAndSettle();
expect(selectedFiles.files, isEmpty);
+ expect(
+ padding.value,
+ MediaQuery.paddingOf(tester.element(find.byType(Gallery))).bottom,
+ );
expect(find.byType(AlbumCoverActionButton), findsNWidgets(2));
expect(find.byTooltip("Sort"), findsOneWidget);
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.dart
index 17b037832e..e75879f4c6 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
@@ -286,4 +286,14 @@ Future<void> _pumpSheet(
),
);
await tester.pumpAndSettle();
+ final boundaries = tester.state<GalleryBoundariesProviderState>(
+ find.byType(GalleryBoundariesProvider),
+ );
+ final sheet = tester.widget<DraggableScrollableSheet>(
+ find.byType(DraggableScrollableSheet),
+ );
+ expect(
+ boundaries.selectionSheetMinHeightNotifier.value,
+ closeTo(sheet.minChildSize * size.height, 0.01),
+ );
}