Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Enable gallery pinch in photo selection flows

ashil-pilotafc1dfaf8f59
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_grid_zoom_layout.dart b/mobile/apps/photos/lib/models/gallery/gallery_grid_zoom_layout.dart
index 8d6fb5b0c0..776badeb21 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_grid_zoom_layout.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_grid_zoom_layout.dart
@@ -22,12 +22,16 @@ class GalleryGridZoomHeader {
const GalleryGridZoomHeader({
required this.id,
required this.firstFile,
+ required this.firstFileIndex,
+ required this.endFileIndex,
required this.groupType,
required this.rect,
});
final String id;
final EnteFile firstFile;
+ final int firstFileIndex;
+ final int endFileIndex;
final GroupType groupType;
final Rect rect;
@@ -224,6 +228,8 @@ class GalleryGridZoomLayout {
GalleryGridZoomHeader(
id: "${groupType.name}:${section.firstFileIndex}",
firstFile: _files[section.firstFileIndex],
+ firstFileIndex: section.firstFileIndex,
+ endFileIndex: section.endFileIndex,
groupType: groupType,
rect: Rect.fromLTWH(0, section.top, width, headerExtent),
);
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
index 2a74c2a0c9..76840f5b57 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart
@@ -29,6 +29,23 @@ import "package:photos/ui/viewer/gallery/state/gallery_context_state.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
import "package:photos/ui/viewer/gallery/state/gallery_swipe_helper.dart";
+Color galleryFileSelectionColor(
+ BuildContext context,
+ EnteFile file,
+ int? currentUserID,
+) {
+ if (file.isUploaded &&
+ file.ownerID != null &&
+ file.ownerID != currentUserID) {
+ final owner = CollectionsService.instance.resolveUserIdentity(
+ file.ownerID!,
+ file.collectionID,
+ );
+ return getUserAvatarColor(context, owner);
+ }
+ return Colors.white;
+}
+
class GalleryFileWidget extends StatefulWidget {
final EnteFile file;
final SelectedFiles? selectedFiles;
@@ -132,17 +149,6 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
Widget _buildFileContent(BuildContext context) {
final disableSelection =
GalleryContextState.of(context)?.disableSelection ?? false;
- Color selectionColor = Colors.white;
- if (_isFileSelected &&
- widget.file.isUploaded &&
- widget.file.ownerID != null &&
- widget.file.ownerID != widget.currentUserID) {
- final owner = CollectionsService.instance.resolveUserIdentity(
- widget.file.ownerID!,
- widget.file.collectionID,
- );
- selectionColor = getUserAvatarColor(context, owner);
- }
final String heroTag = widget.tag + widget.file.tag;
final isPhoto =
widget.file.fileType == FileType.image ||
@@ -225,7 +231,11 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
child: SelectAllStatusIcon(
isSelected: true,
size: 16,
- selectedFillColor: selectionColor,
+ selectedFillColor: galleryFileSelectionColor(
+ context,
+ widget.file,
+ widget.currentUserID,
+ ),
selectedTickCutsOut: true,
),
),
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
index 0003f4a2c2..7688010250 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/group/group_header_widget.dart
@@ -20,6 +20,7 @@ class GroupHeaderWidget extends StatefulWidget {
final List<EnteFile> filesInGroup;
final SelectedFiles? selectedFiles;
final bool showSelectAll;
+ final bool? allSelectedOverride;
final bool showGalleryLayoutSettingCTA;
final Widget? action;
final bool showTrailingIcons;
@@ -33,6 +34,7 @@ class GroupHeaderWidget extends StatefulWidget {
required this.filesInGroup,
required this.selectedFiles,
required this.showSelectAll,
+ this.allSelectedOverride,
this.showGalleryLayoutSettingCTA = false,
this.action,
this.height,
@@ -63,7 +65,8 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
@override
void didUpdateWidget(covariant GroupHeaderWidget oldWidget) {
super.didUpdateWidget(oldWidget);
- if (oldWidget.title != widget.title) {
+ if (oldWidget.title != widget.title ||
+ oldWidget.allSelectedOverride != widget.allSelectedOverride) {
_areAllFromGroupSelectedNotifier.value = _areAllFromGroupSelected();
}
}
@@ -217,6 +220,7 @@ class _GroupHeaderWidgetState extends State<GroupHeaderWidget> {
}
bool _areAllFromGroupSelected() {
+ if (widget.allSelectedOverride != null) return widget.allSelectedOverride!;
final selectedFiles = widget.selectedFiles?.files;
if (selectedFiles == null || selectedFiles.isEmpty) return false;
return widget.filesInGroup
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
index 4dfd9f1a0e..a4a565609a 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/swipe_selectable_file_widget.dart
@@ -44,7 +44,7 @@ class _SwipeSelectableFileWidgetState extends State<SwipeSelectableFileWidget> {
widget.selectedFiles!.files.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted &&
- isSwipeActive &&
+ swipeActiveNotifier?.value == true &&
_isPointerInside &&
!swipeHelper.isActive) {
swipeHelper.startSelection(widget.file);
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index 4f0cb566db..700bc74ca2 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -1010,9 +1010,6 @@ class GalleryState extends State<Gallery> {
enabled:
!widget.disableScroll &&
widget.layoutTypeOverride == null &&
- !widget.limitSelectionToOne &&
- !widget.inSelectionMode &&
- !(widget.selectedFiles?.files.isNotEmpty ?? false) &&
_allGalleryFiles.isNotEmpty,
onCommit: _commitGridZoom,
showSelectAll: widget.showSelectAll && !widget.limitSelectionToOne,
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_grid_zoom.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_grid_zoom.dart
index 460881cff4..77a58e8db5 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_grid_zoom.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_grid_zoom.dart
@@ -6,10 +6,13 @@ import "package:flutter/material.dart";
import "package:flutter/scheduler.dart";
import "package:logging/logging.dart";
import "package:photos/core/constants.dart";
+import "package:photos/models/file/dummy_file.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/gallery/gallery_grid_zoom_layout.dart";
import "package:photos/models/gallery/gallery_groups.dart";
+import "package:photos/ui/viewer/actions/select_all_status_icon.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
+import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";
@@ -79,6 +82,7 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
super.initState();
_density.addListener(_updateSegment);
_justifiedCatchup.addListener(_applyRequestedDensity);
+ widget.groups.selectedFiles?.addListener(_selectionChanged);
}
@override
@@ -132,6 +136,11 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
@override
void didUpdateWidget(GalleryGridZoom oldWidget) {
super.didUpdateWidget(oldWidget);
+ if (oldWidget.groups.selectedFiles != widget.groups.selectedFiles) {
+ oldWidget.groups.selectedFiles?.removeListener(_selectionChanged);
+ widget.groups.selectedFiles?.addListener(_selectionChanged);
+ _clear();
+ }
if (oldWidget.groups != widget.groups) _warmLayouts();
if (!widget.enabled ||
!identical(oldWidget.groups.allFiles, widget.groups.allFiles) ||
@@ -141,6 +150,10 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
}
}
+ void _selectionChanged() {
+ if (_session != null) setState(_clear);
+ }
+
void _start(Offset focalPoint) {
if (_session != null ||
!widget.enabled ||
@@ -313,20 +326,40 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
final last = end.tileForIndex(index)!;
final from = first.rect.shift(Offset(0, startOrigin));
final to = last.rect.shift(Offset(0, endOrigin));
- items.add(
- _ZoomItem(
- key: ValueKey(("gallery-grid-zoom-tile", index)),
- from: from,
- to: to,
- fromOpacity: from.overlaps(viewport) ? 1 : 0,
- toOpacity: to.overlaps(viewport) ? 1 : 0,
- fadeDuringReflow:
- from.overlaps(viewport) &&
- to.overlaps(viewport) &&
- (from.left - to.left).abs() > (from.width + to.width) / 2,
- file: first.file,
- ),
+ final isSelected =
+ widget.groups.selectedFiles?.files.contains(first.file) ?? false;
+ final item = _ZoomItem(
+ key: ValueKey(("gallery-grid-zoom-tile", index)),
+ from: from,
+ to: to,
+ fromOpacity: from.overlaps(viewport) ? 1 : 0,
+ toOpacity: to.overlaps(viewport) ? 1 : 0,
+ fadeDuringReflow:
+ from.overlaps(viewport) &&
+ to.overlaps(viewport) &&
+ (from.left - to.left).abs() > (from.width + to.width) / 2,
+ file: first.file,
+ fileIndex: index,
+ isSelected: isSelected,
);
+ items.add(item);
+ if (isSelected) {
+ items.add(
+ _ZoomItem(
+ key: ValueKey(("gallery-grid-zoom-selection", index)),
+ from: Rect.fromLTWH(from.right - 20, from.top + 4, 16, 16),
+ to: Rect.fromLTWH(to.right - 20, to.top + 4, 16, 16),
+ fromOpacity: item.fromOpacity,
+ toOpacity: item.toOpacity,
+ fadeDuringReflow: item.fadeDuringReflow,
+ selectionColor: galleryFileSelectionColor(
+ context,
+ first.file,
+ widget.groups.currentUserID,
+ ),
+ ),
+ );
+ }
}
Map<String, ({GalleryGridZoomHeader header, Rect rect})> headers(
GalleryGridZoomLayout layout,
@@ -367,6 +400,16 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
for (final id in {...startHeaders.keys, ...endHeaders.keys}) {
final first = startHeaders[id];
final last = endHeaders[id];
+ final header = (first ?? last)!.header;
+ final allSelected = session.headerSelections.putIfAbsent(id, () {
+ final selected = widget.groups.selectedFiles?.files;
+ return selected != null &&
+ selected.isNotEmpty &&
+ widget.groups.allFiles
+ .getRange(header.firstFileIndex, header.endFileIndex)
+ .where((file) => file is! DummyFile)
+ .every(selected.contains);
+ });
items.add(
_ZoomItem(
key: ValueKey(("gallery-grid-zoom-header", id)),
@@ -374,7 +417,8 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
to: last?.rect ?? first!.rect,
fromOpacity: first == null ? 0 : 1,
toOpacity: last == null ? 0 : 1,
- header: (first ?? last)!.header,
+ header: header,
+ isSelected: allSelected,
pinnedFrom: id == pinnedFrom,
pinnedTo: id == pinnedTo,
headerActions:
@@ -457,6 +501,7 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
@override
void dispose() {
_warmupTimer?.cancel();
+ widget.groups.selectedFiles?.removeListener(_selectionChanged);
_clear();
_density.dispose();
_opacity.dispose();
@@ -464,6 +509,38 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
super.dispose();
}
+ Widget _buildThumbnail(_ZoomSession session, _ZoomItem item, EnteFile file) {
+ final image = GalleryZoomImage(
+ animation: _density,
+ lower: _lower,
+ from: item.from,
+ to: item.to,
+ image: session.images[file],
+ child: session.images[file] != null
+ ? const SizedBox.expand()
+ : widget.thumbnailBuilder?.call(file) ??
+ ThumbnailWidget(
+ file,
+ rawThumbnail: true,
+ thumbnailSize: session.initialColumns <= 3
+ ? thumbnailLargeSize
+ : thumbnailSmallSize,
+ useCachedThumbnailAsPlaceholder: true,
+ ),
+ );
+ if (!item.isSelected) return image;
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ image,
+ ColoredBox(
+ key: ValueKey(("gallery-grid-zoom-selection-shade", item.fileIndex!)),
+ color: const Color.fromARGB(102, 0, 0, 0),
+ ),
+ ],
+ );
+ }
+
@override
Widget build(BuildContext context) {
final session = _session;
@@ -501,34 +578,22 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
),
children: [
for (final item in _items)
- if (item.file case final file?)
+ if (item.selectionColor case final color?)
+ RepaintBoundary(
+ key: item.key,
+ child: SelectAllStatusIcon(
+ isSelected: true,
+ size: 16,
+ selectedFillColor: color,
+ selectedTickCutsOut: true,
+ ),
+ )
+ else if (item.file case final file?)
RepaintBoundary(
key: item.key,
child: ClipRRect(
borderRadius: BorderRadius.circular(1),
- child: GalleryZoomImage(
- animation: _density,
- lower: _lower,
- from: item.from,
- to: item.to,
- image: session.images[file],
- child: session.images[file] != null
- ? const SizedBox.expand()
- : widget.thumbnailBuilder?.call(
- file,
- ) ??
- ThumbnailWidget(
- file,
- rawThumbnail: true,
- thumbnailSize:
- session.initialColumns <=
- 3
- ? thumbnailLargeSize
- : thumbnailSmallSize,
- useCachedThumbnailAsPlaceholder:
- true,
- ),
- ),
+ child: _buildThumbnail(session, item, file),
),
)
else
@@ -541,6 +606,7 @@ class _GalleryGridZoomState extends State<GalleryGridZoom>
gridSize: session.initialColumns,
filesInGroup: const [],
selectedFiles: null,
+ allSelectedOverride: item.isSelected,
showSelectAll: widget.showSelectAll,
showGalleryLayoutSettingCTA:
item.headerActions &&
@@ -583,6 +649,7 @@ class _ZoomSession {
final Size size;
final double clipTop;
final Map<EnteFile, ui.Image> images;
+ final Map<String, bool> headerSelections = {};
Future<void>? justifiedReady;
}
@@ -594,6 +661,9 @@ class _ZoomItem {
required this.fromOpacity,
required this.toOpacity,
this.file,
+ this.fileIndex,
+ this.isSelected = false,
+ this.selectionColor,
this.header,
this.pinnedFrom = false,
this.pinnedTo = false,
@@ -606,6 +676,9 @@ class _ZoomItem {
final double fromOpacity;
final double toOpacity;
final EnteFile? file;
+ final int? fileIndex;
+ final bool isSelected;
+ final Color? selectionColor;
final GalleryGridZoomHeader? header;
final bool pinnedFrom;
final bool pinnedTo;
@@ -631,12 +704,14 @@ class _ZoomFlowDelegate extends FlowDelegate {
@override
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) =>
- BoxConstraints.tight(
- Size(
- items[i].file != null ? tileExtent : constraints.maxWidth,
- items[i].file != null ? tileExtent : headerExtent,
- ),
- );
+ items[i].selectionColor != null
+ ? const BoxConstraints.tightFor(width: 16, height: 16)
+ : BoxConstraints.tight(
+ Size(
+ items[i].file != null ? tileExtent : constraints.maxWidth,
+ items[i].file != null ? tileExtent : headerExtent,
+ ),
+ );
@override
void paintChildren(FlowPaintingContext context) {
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_grid_zoom_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_grid_zoom_test.dart
index 60fa19a732..cab948284d 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_grid_zoom_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_grid_zoom_test.dart
@@ -11,8 +11,11 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/gallery/gallery_groups.dart";
import "package:photos/models/metadata/file_magic.dart";
+import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
import "package:photos/settings/local_settings.dart";
+import "package:photos/ui/viewer/actions/select_all_status_icon.dart";
+import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";
import "package:photos/ui/viewer/gallery/component/group/type.dart";
import "package:photos/ui/viewer/gallery/gallery_grid_zoom.dart";
import "package:shared_preferences/shared_preferences.dart";
@@ -167,6 +170,112 @@ void main() {
await tester.pump();
});
+ testWidgets(
+ "selection stays aligned through justified morphs and clearing it cancels",
+ (tester) async {
+ for (final sourceLayout in [
+ GalleryLayoutType.grid,
+ GalleryLayoutType.justified,
+ ]) {
+ await localSettings.setPhotoGridSize(3);
+ await localSettings.setGalleryLayoutType(sourceLayout);
+ final selection = SelectedFiles();
+ final fixture = _ZoomFixture(
+ fileCount: 9,
+ leadingExtent: 56,
+ groupType: GroupType.day,
+ selectedFiles: selection,
+ );
+ addTearDown(selection.dispose);
+ addTearDown(fixture.controller.dispose);
+ selection.selectAll(fixture.files.toSet());
+ await fixture.mount(tester);
+ final sourceTile = fixture.groups
+ .gridZoomLayout(
+ columns: fixture.groups.crossAxisCount,
+ headerExtent: fixture.headerExtent,
+ )
+ .tileForIndex(0)!;
+ final focalPoint =
+ sourceTile.rect.center + Offset(0, fixture.leadingExtent);
+ const halfSpan = 25.0;
+ final first = await tester.startGesture(
+ focalPoint - const Offset(halfSpan, 0),
+ pointer: 1,
+ );
+ final second = await tester.startGesture(
+ focalPoint + const Offset(halfSpan, 0),
+ pointer: 2,
+ );
+ await tester.pump();
+ final tile = find.byKey(const ValueKey(("gallery-grid-zoom-tile", 0)));
+ final initialSize = tester.getRect(tile).size;
+ final marker = find.byKey(
+ const ValueKey(("gallery-grid-zoom-selection", 0)),
+ );
+ final shade = find.byKey(
+ const ValueKey(("gallery-grid-zoom-selection-shade", 0)),
+ );
+ for (final scale
+ in sourceLayout == GalleryLayoutType.grid
+ ? [1.4, 2.4]
+ : [0.8, 0.6]) {
+ await first.moveTo(focalPoint - Offset(halfSpan * scale, 0));
+ await second.moveTo(focalPoint + Offset(halfSpan * scale, 0));
+ await tester.pump();
+ final tileRect = tester.getRect(tile);
+ final markerRect = tester.getRect(marker);
+ expect(tileRect.size, isNot(initialSize));
+ expect(markerRect.width, closeTo(16, 0.001));
+ expect(markerRect.height, closeTo(16, 0.001));
+ expect(markerRect.right, closeTo(tileRect.right - 4, 0.001));
+ expect(markerRect.top, closeTo(tileRect.top + 4, 0.001));
+ expect(tester.getRect(shade), tileRect);
+ expect(
+ tester.widget<ColoredBox>(shade).color,
+ const Color.fromARGB(102, 0, 0, 0),
+ );
+ expect(
+ tester
+ .widget<SelectAllStatusIcon>(
+ find.descendant(
+ of: marker,
+ matching: find.byType(SelectAllStatusIcon),
+ ),
+ )
+ .isSelected,
+ isTrue,
+ );
+ final selectedHeader = find.descendant(
+ of: find.descendant(
+ of: _overlay,
+ matching: find.byType(GroupHeaderWidget),
+ ),
+ matching: find.byType(SelectAllStatusIcon),
+ );
+ expect(selectedHeader, findsOneWidget);
+ expect(
+ tester.widget<SelectAllStatusIcon>(selectedHeader).isSelected,
+ isTrue,
+ );
+ expect(selection.files, unorderedEquals(fixture.files));
+ }
+
+ selection.clearAll(fireEvent: false);
+ await tester.pump();
+ expect(_overlay, findsNothing);
+ await first.up();
+ await second.up();
+ await tester.pumpAndSettle();
+ expect(fixture.commits, isEmpty);
+ expect(selection.files, isEmpty);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump();
+ }
+ },
+ );
+
testWidgets("morphs into the justified layout and back to three columns", (
tester,
) async {
@@ -486,21 +595,29 @@ void main() {
Finder get _overlay => find.byKey(const ValueKey("gallery-grid-zoom-overlay"));
class _ZoomFixture {
- _ZoomFixture({int fileCount = 1200, this.leadingExtent = contentTop})
- : files = List<EnteFile>.generate(
- fileCount,
- (index) => EnteFile()
- ..generatedID = index + 1
- ..creationTime = DateTime(2026, 8, 19).microsecondsSinceEpoch
- ..fileType = FileType.image
- ..pubMagicMetadata = PubMagicMetadata(
- w: index.isEven ? 1600 : 900,
- h: index.isEven ? 900 : 1600,
- ),
- );
+ _ZoomFixture({
+ int fileCount = 1200,
+ this.leadingExtent = contentTop,
+ this.groupType = GroupType.none,
+ this.selectedFiles,
+ }) : files = List<EnteFile>.generate(
+ fileCount,
+ (index) => EnteFile()
+ ..generatedID = index + 1
+ ..creationTime = DateTime(2026, 8, 19).microsecondsSinceEpoch
+ ..fileType = FileType.image
+ ..pubMagicMetadata = PubMagicMetadata(
+ w: index.isEven ? 1600 : 900,
+ h: index.isEven ? 900 : 1600,
+ ),
+ );
static const contentTop = 112.0;
final double leadingExtent;
+ final GroupType groupType;
+ final SelectedFiles? selectedFiles;
+ double get headerExtent =>
+ groupType == GroupType.none ? GalleryGroups.spacing : 48;
final controller = ScrollController();
final commits = <(int, double)>[];
List<EnteFile> files;
@@ -510,21 +627,19 @@ class _ZoomFixture {
GalleryGroups _groups() => GalleryGroups(
allFiles: files,
- groupType: GroupType.none,
+ groupType: groupType,
widthAvailable: 400,
- selectedFiles: null,
+ selectedFiles: selectedFiles,
tagPrefix: "zoom_test_",
- groupHeaderExtent: GalleryGroups.spacing,
- showSelectAll: false,
+ groupHeaderExtent: headerExtent,
+ showSelectAll: selectedFiles != null,
);
Future<void> mount(WidgetTester tester, {bool prewarm = true}) async {
groups = _groups();
if (prewarm) {
await tester.runAsync(
- () => groups.prepareJustifiedZoomLayout(
- headerExtent: GalleryGroups.spacing,
- ),
+ () => groups.prepareJustifiedZoomLayout(headerExtent: headerExtent),
);
}
await tester.pumpWidget(
@@ -546,6 +661,7 @@ class _ZoomFixture {
sectionOrigin: () => leadingExtent - controller.offset,
appBarHeight: 56,
pinHeaders: false,
+ showSelectAll: selectedFiles != null,
enabled: true,
onCommit: (columns, scrollOffset) async {
commits.add((columns, scrollOffset));
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
index c41047a464..7a24d8b70b 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/gallery_layout_changed_event_test.dart
@@ -15,6 +15,7 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/file_load_result.dart";
import "package:photos/models/metadata/file_magic.dart";
+import "package:photos/models/selected_files.dart";
import "package:photos/service_locator.dart";
import "package:photos/settings/local_settings.dart";
import "package:photos/ui/settings/gallery_settings_screen.dart";
@@ -57,6 +58,118 @@ void main() {
await localSettings.setGalleryLayoutType(GalleryLayoutType.grid);
});
+ testWidgets(
+ "pinching selection galleries changes density without changing selection",
+ (tester) async {
+ for (final mode in ["sheet", "single", "selected"]) {
+ await localSettings.setPhotoGridSize(4);
+ final galleryKey = GlobalKey<GalleryState>();
+ final files = List.generate(
+ 12,
+ (index) => EnteFile()
+ ..generatedID = index + 1
+ ..creationTime = DateTime(2026, 8, 19).microsecondsSinceEpoch
+ ..fileType = FileType.image
+ ..title = "photo-$index.jpg",
+ );
+ final selectedFiles = SelectedFiles();
+ if (mode == "selected") selectedFiles.selectAll({files.first});
+ var selectionChanges = 0;
+ selectedFiles.addListener(() => selectionChanges++);
+ final selectionBefore = selectedFiles.files.toSet();
+ await _mountPinchGallery(
+ tester,
+ Gallery(
+ key: galleryKey,
+ asyncLoader: (start, end, {limit, asc}) async =>
+ FileLoadResult(files, false),
+ selectedFiles: selectedFiles,
+ tagPrefix: "pinch_$mode",
+ enableFileGrouping: false,
+ inSelectionMode: mode == "sheet",
+ limitSelectionToOne: mode == "single",
+ showSelectAll: false,
+ ),
+ );
+ selectionChanges = 0;
+
+ final first = await tester.startGesture(
+ const Offset(120, 150),
+ pointer: 1,
+ );
+ final second = await tester.startGesture(
+ const Offset(280, 150),
+ pointer: 2,
+ );
+ await first.moveTo(const Offset(150, 150));
+ await second.moveTo(const Offset(250, 150));
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey("gallery-grid-zoom-overlay")),
+ findsOneWidget,
+ reason: mode,
+ );
+ expect(localSettings.getPhotoGridSize(), 4, reason: mode);
+ await first.up();
+ await second.up();
+ await tester.pumpAndSettle();
+
+ expect(localSettings.getPhotoGridSize(), 5, reason: mode);
+ expect(galleryKey.currentState!.galleryGroups!.crossAxisCount, 5);
+ expect(selectedFiles.files, unorderedEquals(selectionBefore));
+ expect(selectionChanges, 0, reason: mode);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(milliseconds: 100));
+ selectedFiles.dispose();
+ }
+ },
+ );
+
+ testWidgets("fixed-layout and non-scrollable galleries ignore pinches", (
+ tester,
+ ) async {
+ for (final fixedLayout in [false, true]) {
+ await localSettings.setPhotoGridSize(4);
+ final galleryKey = GlobalKey<GalleryState>();
+ await _mountPinchGallery(
+ tester,
+ Gallery(
+ key: galleryKey,
+ asyncLoader: (start, end, {limit, asc}) async =>
+ FileLoadResult(List.generate(12, _justifiedTestFile), false),
+ tagPrefix: "pinch_excluded",
+ enableFileGrouping: false,
+ disableScroll: !fixedLayout,
+ layoutTypeOverride: fixedLayout ? GalleryLayoutType.grid : null,
+ ),
+ );
+ final first = await tester.startGesture(
+ const Offset(120, 150),
+ pointer: 1,
+ );
+ final second = await tester.startGesture(
+ const Offset(280, 150),
+ pointer: 2,
+ );
+ await first.moveTo(const Offset(150, 150));
+ await second.moveTo(const Offset(250, 150));
+ await tester.pump();
+ expect(
+ find.byKey(const ValueKey("gallery-grid-zoom-overlay")),
+ findsNothing,
+ );
+ await first.up();
+ await second.up();
+ await tester.pumpAndSettle();
+ expect(localSettings.getPhotoGridSize(), 4);
+ expect(galleryKey.currentState!.galleryGroups!.crossAxisCount, 4);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(milliseconds: 100));
+ }
+ });
+
testWidgets("keeps the current gallery controller after an animated swap", (
tester,
) async {
@@ -554,6 +667,21 @@ Widget _galleryHost(Gallery gallery) {
return GalleryBoundariesProvider(child: GalleryFilesState(child: gallery));
}
+Future<void> _mountPinchGallery(WidgetTester tester, Gallery gallery) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: StringsLocalizations.localizationsDelegates,
+ supportedLocales: StringsLocalizations.supportedLocales,
+ home: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(width: 400, height: 600, child: _galleryHost(gallery)),
+ ),
+ ),
+ );
+ await tester.pumpAndSettle();
+}
+
DummyFile _dummyFile(String groupID) {
return DummyFile(groupID: groupID, index: 0)
..creationTime = DateTime(2026, 8, 19).microsecondsSinceEpoch;
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/swipe_selection_pinch_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/swipe_selection_pinch_test.dart
index 136ae47865..fbef2cef85 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/swipe_selection_pinch_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/swipe_selection_pinch_test.dart
@@ -117,5 +117,25 @@ void main() {
await next.up();
expect(swipeActive.value, isFalse);
expect(helper.isActive, isFalse);
+
+ final pending = await tester.startGesture(
+ const Offset(250, 550),
+ pointer: 4,
+ );
+ final beforeDeferredSelection = selectedFiles.files.toSet();
+ swipeActive.value = true;
+ tester.binding.addPostFrameCallback((_) {
+ tester.binding.handlePointerEvent(
+ const PointerDownEvent(pointer: 5, position: Offset(450, 550)),
+ );
+ });
+ await tester.pump();
+ expect(swipeActive.value, isFalse);
+ expect(helper.isActive, isFalse);
+ expect(selectedFiles.files, unorderedEquals(beforeDeferredSelection));
+ tester.binding.handlePointerEvent(
+ const PointerUpEvent(pointer: 5, position: Offset(450, 550)),
+ );
+ await pending.up();
});
}