Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Prevent file selection during vertical scrolling

ashilkn972fcbaae822
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 47d052f0a8..46dbd28d87 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
@@ -86,18 +86,24 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {
shouldShowOwnerAvatar: !_isFileSelected,
shouldShowVideoDuration: true,
);
+ final swipeActiveNotifier =
+ GallerySwipeHelper.swipeActiveNotifierOf(context);
+
return TouchCrossDetector(
onPointerDown: (event) {
_currentPointerId = event.pointer;
- if (swipeHelper != null &&
- widget.selectedFiles != null &&
- widget.selectedFiles!.files.isNotEmpty) {
- swipeHelper.startSelection(widget.file);
- }
+ // Don't start selection immediately - wait for horizontal swipe detection
},
onEnter: (event) {
- if (swipeHelper?.isActive ?? false) {
- swipeHelper!.updateSelection(widget.file);
+ // Check if horizontal swipe is active before starting or updating selection
+ if (swipeActiveNotifier?.value == true && swipeHelper != null) {
+ if (!swipeHelper.isActive) {
+ // Start selection when first entering a file during active swipe
+ swipeHelper.startSelection(widget.file);
+ } else {
+ // Update selection for subsequent files
+ swipeHelper.updateSelection(widget.file);
+ }
}
},
onExit: (event) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
index c7c6bbb0a1..26c7e6f74e 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart
@@ -293,6 +293,7 @@ class GalleryState extends State<Gallery> {
});
widget.selectedFiles?.addListener(_selectedFilesListener);
+
}
@override
@@ -469,13 +470,6 @@ class GalleryState extends State<Gallery> {
}
}
- void _checkAndUpdateSwipeStatus() {
- // Update swipe active status based on helper state
- final isActive = _swipeHelper?.isActive ?? false;
- if (_swipeActiveNotifier.value != isActive) {
- _swipeActiveNotifier.value = isActive;
- }
- }
Future<FileLoadResult> _loadFiles({int? limit}) async {
_logger.info("Loading ${limit ?? "all"} files");
@@ -583,6 +577,7 @@ class GalleryState extends State<Gallery> {
}
return GallerySwipeHelper(
helper: _swipeHelper,
+ swipeActiveNotifier: _swipeActiveNotifier,
child: Listener(
onPointerMove: (event) {
// Only check for horizontal swipe if files are selected and swipe is not already active
@@ -593,15 +588,21 @@ class GalleryState extends State<Gallery> {
final dx = event.delta.dx.abs();
final dy = event.delta.dy.abs();
if (dx > dy * 2 && dx > 0.1) {
- // Horizontal swipe detected, check if swipe helper is active
- _checkAndUpdateSwipeStatus();
+ // Horizontal swipe detected, activate swipe mode
+ _swipeActiveNotifier.value = true;
}
}
- // To handle case where pointer is dragged downwards after first selection in gallery
+ // To handle case where pointer is dragged after first selection in gallery
else if (widget.selectedFiles != null &&
widget.selectedFiles!.files.isNotEmpty &&
- widget.selectedFiles!.files.length == 1) {
- _checkAndUpdateSwipeStatus();
+ widget.selectedFiles!.files.length == 1 &&
+ !_swipeActiveNotifier.value) {
+ // Check if this is horizontal movement when only one file is selected
+ final dx = event.delta.dx.abs();
+ final dy = event.delta.dy.abs();
+ if (dx > dy * 2 && dx > 0.1) {
+ _swipeActiveNotifier.value = true;
+ }
}
},
onPointerUp: (_) {
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
index 225dea00e2..94ccfa58a0 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_swipe_helper.dart
@@ -7,10 +7,12 @@ import 'package:photos/ui/viewer/gallery/swipe_to_select_helper.dart';
/// without passing it through multiple widget constructors.
class GallerySwipeHelper extends InheritedWidget {
final SwipeToSelectHelper? helper;
+ final ValueNotifier<bool>? swipeActiveNotifier;
const GallerySwipeHelper({
super.key,
this.helper,
+ this.swipeActiveNotifier,
required super.child,
});
@@ -21,9 +23,17 @@ class GallerySwipeHelper extends InheritedWidget {
return widget?.helper;
}
+ /// Get the swipeActiveNotifier from the nearest ancestor GallerySwipeHelper.
+ static ValueNotifier<bool>? swipeActiveNotifierOf(BuildContext context) {
+ final widget =
+ context.dependOnInheritedWidgetOfExactType<GallerySwipeHelper>();
+ return widget?.swipeActiveNotifier;
+ }
+
@override
bool updateShouldNotify(GallerySwipeHelper oldWidget) {
- // Only notify if the helper instance changes
- return helper != oldWidget.helper;
+ // Notify if either the helper instance or notifier changes
+ return helper != oldWidget.helper ||
+ swipeActiveNotifier != oldWidget.swipeActiveNotifier;
}
}