Skip to content

armgit / ente

Public Imported from GitHub
0

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

Optimize boundary reporting for selection state transitions

ashilkn0b4b659b5d46
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index 9da8adcbf7..3222a1cbd1 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -48,19 +48,15 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>
late GalleryType _galleryType;
SearchFilterDataProvider? _searchFilterDataProvider;
bool? _galleryInitialFilterStillApplied;
+ bool _wasEmpty = true;
@override
void initState() {
super.initState();
_galleryType = widget.galleryType;
+ _wasEmpty = widget.selectedFiles.files.isEmpty;
widget.selectedFiles.addListener(_selectedFilesListener);
-
- // Report boundary when selection changes
- widget.selectedFiles.addListener(() {
- if (widget.selectedFiles.files.isNotEmpty) {
- reportBoundary(BoundaryPosition.bottom);
- }
- });
+ widget.selectedFiles.addListener(_boundaryUpdateListener);
if (widget.selectedFiles.files.isNotEmpty) {
_selectedFilesListener();
@@ -71,6 +67,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>
void dispose() {
_hasSelectedFilesNotifier.dispose();
widget.selectedFiles.removeListener(_selectedFilesListener);
+ widget.selectedFiles.removeListener(_boundaryUpdateListener);
_searchFilterDataProvider?.removeListener(
listener: _filterAppliedListener,
fromApplied: true,
@@ -187,6 +184,17 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>
_hasSelectedFilesNotifier.value = widget.selectedFiles.files.isNotEmpty;
}
+ void _boundaryUpdateListener() {
+ final isEmpty = widget.selectedFiles.files.isEmpty;
+
+ // Only report boundary on empty ↔ non-empty transitions
+ if (_wasEmpty != isEmpty) {
+ // Report boundary - will set to null if widget is not visible
+ reportBoundary(BoundaryPosition.bottom);
+ _wasEmpty = isEmpty;
+ }
+ }
+
void _filterAppliedListener() {
widget.selectedFiles.clearAll();
_updateGalleryTypeIfRequired();
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
index 3607f26541..5fd9999126 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/boundary_reporter_mixin.dart
@@ -19,6 +19,14 @@ mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
_boundaryUpdateTimer = Timer(const Duration(milliseconds: 100), () {
if (!mounted) return;
+ final provider = GalleryBoundariesProvider.of(context);
+ assert(
+ provider != null,
+ 'GalleryBoundariesProvider not found in context. '
+ 'Ensure BoundaryReporter is used within a GalleryBoundariesProvider.',
+ );
+ if (provider == null) return;
+
final renderBox =
_boundaryKey.currentContext?.findRenderObject() as RenderBox?;
if (renderBox != null && renderBox.hasSize) {
@@ -27,13 +35,17 @@ mixin BoundaryReporter<T extends StatefulWidget> on State<T> {
? offset.dy + renderBox.size.height // Bottom edge of top widget
: offset.dy; // Top edge of bottom widget
- final provider = GalleryBoundariesProvider.of(context);
- if (provider != null) {
- if (position == BoundaryPosition.top) {
- provider.setTopBoundary(boundary);
- } else {
- provider.setBottomBoundary(boundary);
- }
+ if (position == BoundaryPosition.top) {
+ provider.setTopBoundary(boundary);
+ } else {
+ provider.setBottomBoundary(boundary);
+ }
+ } else {
+ // RenderBox not available (widget hidden/removed) - clear boundary
+ if (position == BoundaryPosition.top) {
+ provider.setTopBoundary(null);
+ } else {
+ provider.setBottomBoundary(null);
}
}
});