Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(photos): address memories viewer review findings

ashilkn679c6ecbfdf1
diff --git a/mobile/apps/photos/changes/memory-viewer-adaptive-scrim.md b/mobile/apps/photos/changes/memory-viewer-adaptive-scrim.md
deleted file mode 100644
index 15dedcc723..0000000000
--- a/mobile/apps/photos/changes/memory-viewer-adaptive-scrim.md
+++ /dev/null
@@ -1 +0,0 @@
-- Improved memory controls with a lighter backdrop that adapts to social actions.
diff --git a/mobile/apps/photos/changes/memory-viewer-backdrop.md b/mobile/apps/photos/changes/memory-viewer-backdrop.md
deleted file mode 100644
index 0a4b2db48c..0000000000
--- a/mobile/apps/photos/changes/memory-viewer-backdrop.md
+++ /dev/null
@@ -1 +0,0 @@
-- Improved the memories viewer with a full-screen blurred backdrop and evenly sized progress indicators.
diff --git a/mobile/apps/photos/changes/memory-viewer-interactions.md b/mobile/apps/photos/changes/memory-viewer-interactions.md
deleted file mode 100644
index 01eb511c46..0000000000
--- a/mobile/apps/photos/changes/memory-viewer-interactions.md
+++ /dev/null
@@ -1 +0,0 @@
-- Refined memory viewer controls, comments, and swipe-up file details.
diff --git a/mobile/apps/photos/lib/services/memories_cache_service.dart b/mobile/apps/photos/lib/services/memories_cache_service.dart
index 75dfb7dc31..20d0685563 100644
--- a/mobile/apps/photos/lib/services/memories_cache_service.dart
+++ b/mobile/apps/photos/lib/services/memories_cache_service.dart
@@ -6,7 +6,6 @@ import "package:flutter/cupertino.dart";
import "package:flutter/foundation.dart" show kDebugMode;
import "package:logging/logging.dart";
import "package:path_provider/path_provider.dart";
-import "package:photos/core/configuration.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/db/files_db.dart";
import "package:photos/db/memories_db.dart";
@@ -51,12 +50,6 @@ class MemoriesCacheService {
static const _shouldUpdateCacheKey = "memories.shouldUpdateCache";
static const _tripMemoryCarryForwardLimit = kTripSurfaceSlots;
- // TEMP(memory-viewer-verification): remove before merge.
- static const _kTempLibraryMemories = bool.fromEnvironment(
- "debugSocialMemoriesMix",
- defaultValue: false,
- );
-
/// Delay is for cache update to be done not during app init, during which a
/// lot of other things are happening.
static const _kCacheUpdateDelay = Duration(seconds: 20);
@@ -69,11 +62,6 @@ class MemoriesCacheService {
: MemoriesDB.instance;
List<SmartMemory>? _cachedMemories;
- List<SmartMemory>? _debugLibraryMemories;
- List<SmartMemory>? _debugLibraryMemoriesSource;
- int? _debugLibraryMemoriesUserID;
- String? _debugLibraryMemoriesInputSignature;
- bool _debugLibraryMemoriesAttempted = false;
List<SmartMemory>? get currentMemoriesSync => _cachedMemories;
bool _shouldUpdate = false;
bool _pendingInitialOfflineCacheUpgrade = false;
@@ -84,7 +72,6 @@ class MemoriesCacheService {
final _memoriesUpdateLock = Lock();
final _memoriesGetLock = Lock();
- final _debugLibraryMemoriesLock = Lock();
MemoriesCacheService(this._prefs) {
_logger.info("MemoriesCacheService constructor");
@@ -629,223 +616,82 @@ class MemoriesCacheService {
_logger.info('Showing memories is disabled in settings, showing none');
return [];
}
- final memories = await _memoriesGetLock.synchronized<List<SmartMemory>>(
- () async {
- if (_cachedMemories != null && _cachedMemories!.isNotEmpty) {
- final currentMemories = _cachedMemories!
- .where((memory) => memory.shouldShowNow())
- .toList();
- if (currentMemories.isNotEmpty) {
- _logger.info("Found memories in memory cache");
- return currentMemories;
- }
- _logger.info(
- "In-memory memories not valid for current window, refreshing cache",
- );
- } else if (onlyUseCache) {
- _logger.info("Only using cache, no memories found");
- return [];
+ return _memoriesGetLock.synchronized(() async {
+ if (_cachedMemories != null && _cachedMemories!.isNotEmpty) {
+ final currentMemories = _cachedMemories!
+ .where((memory) => memory.shouldShowNow())
+ .toList();
+ if (currentMemories.isNotEmpty) {
+ _logger.info("Found memories in memory cache");
+ return currentMemories;
}
- try {
- if (!enableSmartMemories) {
- await _calculateRegularFillers();
- return _cachedMemories!;
+ _logger.info(
+ "In-memory memories not valid for current window, refreshing cache",
+ );
+ } else if (onlyUseCache) {
+ _logger.info("Only using cache, no memories found");
+ return [];
+ }
+ try {
+ if (!enableSmartMemories) {
+ await _calculateRegularFillers();
+ return _cachedMemories!;
+ }
+ final cacheFileExists = await _cacheFileExists();
+ _cachedMemories = await _getMemoriesFromCache();
+ if (_cachedMemories == null || _cachedMemories!.isEmpty) {
+ final shouldRefreshEmptyCache =
+ _cachedMemories == null ||
+ _shouldUpdate ||
+ _timeToUpdateCache() ||
+ lastMemoriesCacheUpdateTime == 0;
+ if (onlyUseCache) {
+ _logger.info("Only using cache, no memories found");
+ return [];
}
- final cacheFileExists = await _cacheFileExists();
- _cachedMemories = await _getMemoriesFromCache();
- if (_cachedMemories == null || _cachedMemories!.isEmpty) {
- final shouldRefreshEmptyCache =
- _cachedMemories == null ||
- _shouldUpdate ||
- _timeToUpdateCache() ||
- lastMemoriesCacheUpdateTime == 0;
- if (onlyUseCache) {
- _logger.info("Only using cache, no memories found");
- return [];
- }
- if (!shouldRefreshEmptyCache) {
- _logger.info("Found fresh empty memories cache");
- return [];
- }
- if (!cacheFileExists) {
+ if (!shouldRefreshEmptyCache) {
+ _logger.info("Found fresh empty memories cache");
+ return [];
+ }
+ if (!cacheFileExists) {
+ _logger.info(
+ "No disk cache (fresh install): serving simple memories, "
+ "smart memories will upgrade in background",
+ );
+ _cachedMemories = await smartMemoriesService.calcSimpleMemories();
+ if (_shouldDeferInitialOfflineCacheUpgrade()) {
+ _pendingInitialOfflineCacheUpgrade = true;
_logger.info(
- "No disk cache (fresh install): serving simple memories, "
- "smart memories will upgrade in background",
+ "Deferring initial offline memories cache upgrade until first import metadata is ready",
+ );
+ } else {
+ unawaited(
+ updateCache(
+ forced: true,
+ ).whenComplete(() => Bus.instance.fire(MemoriesChangedEvent())),
);
- _cachedMemories = await smartMemoriesService.calcSimpleMemories();
- if (_shouldDeferInitialOfflineCacheUpgrade()) {
- _pendingInitialOfflineCacheUpgrade = true;
- _logger.info(
- "Deferring initial offline memories cache upgrade until first import metadata is ready",
- );
- } else {
- unawaited(
- updateCache(forced: true).whenComplete(
- () => Bus.instance.fire(MemoriesChangedEvent()),
- ),
- );
- }
- return _cachedMemories!;
}
- _logger.warning(
- "No memories found in cache, force updating cache. Possible severe caching issue",
- );
- await updateCache(forced: true);
- } else {
- _logger.info("Found memories in cache");
- }
- if (_cachedMemories == null || _cachedMemories!.isEmpty) {
- _logger.severe(
- "No memories found in (computed) cache, getting fillers",
- );
- await _calculateRegularFillers();
+ return _cachedMemories!;
}
- return _cachedMemories!;
- } catch (e, s) {
- _logger.severe("Error in getMemories", e, s);
- return [];
+ _logger.warning(
+ "No memories found in cache, force updating cache. Possible severe caching issue",
+ );
+ await updateCache(forced: true);
+ } else {
+ _logger.info("Found memories in cache");
}
- },
- );
- return _debugBuildLibraryMemories(memories);
- }
-
- // TEMP(memory-viewer-verification): remove before merge. This exposes a
- // broad sample of the account library as several memory cards so that the
- // viewer can be exercised with varied media and sharing states.
- Future<List<SmartMemory>> _debugBuildLibraryMemories(
- List<SmartMemory> memories,
- ) async {
- if (!_kTempLibraryMemories || isLocalGalleryMode || memories.isEmpty) {
- return memories;
- }
- return _debugLibraryMemoriesLock.synchronized(
- () => _debugBuildLibraryMemoriesLocked(memories),
- );
- }
-
- Future<List<SmartMemory>> _debugBuildLibraryMemoriesLocked(
- List<SmartMemory> memories,
- ) async {
- final source = _cachedMemories ?? memories;
- final userID = Configuration.instance.getUserID();
- final inputSignature = memories
- .map((memory) => "${memory.id}:${memory.memories.length}")
- .join("|");
- final sameContext =
- identical(_debugLibraryMemoriesSource, source) &&
- _debugLibraryMemoriesUserID == userID &&
- _debugLibraryMemoriesInputSignature == inputSignature;
- if (!sameContext) {
- _debugLibraryMemories = null;
- _debugLibraryMemoriesAttempted = false;
- _debugLibraryMemoriesSource = source;
- _debugLibraryMemoriesUserID = userID;
- _debugLibraryMemoriesInputSignature = inputSignature;
- }
- if (_debugLibraryMemoriesAttempted) {
- return _debugLibraryMemories ?? memories;
- }
- _debugLibraryMemoriesAttempted = true;
-
- final searchFiles = await SearchService.instance.getAllFilesForSearch();
- final localOnlyFiles = await FilesDB.instance.getUnUploadedLocalFiles();
- final uniqueFiles = <String, EnteFile>{};
- String debugFileID(EnteFile file) {
- final uploadedFileID = file.uploadedFileID;
- if (uploadedFileID != null && uploadedFileID != -1) {
- return "uploaded:$uploadedFileID";
- }
- final localID = file.localID;
- if (localID != null && localID.isNotEmpty) {
- return "local:$localID";
- }
- final generatedID = file.generatedID;
- return generatedID != null
- ? "generated:$generatedID"
- : "object:${identityHashCode(file)}";
- }
-
- void addFiles(Iterable<EnteFile> files) {
- for (final file in files) {
- if (file.creationTime == null) continue;
- uniqueFiles.putIfAbsent(debugFileID(file), () => file);
+ if (_cachedMemories == null || _cachedMemories!.isEmpty) {
+ _logger.severe(
+ "No memories found in (computed) cache, getting fillers",
+ );
+ await _calculateRegularFillers();
+ }
+ return _cachedMemories!;
+ } catch (e, s) {
+ _logger.severe("Error in getMemories", e, s);
+ return [];
}
- }
-
- addFiles(searchFiles);
- addFiles(localOnlyFiles);
- if (uniqueFiles.isEmpty) {
- _logger.warning("TEMP library memories unavailable: no usable files");
- return memories;
- }
-
- final sortedFiles = uniqueFiles.values.toList()
- ..sort((first, second) {
- final creationOrder = second.creationTime!.compareTo(
- first.creationTime!,
- );
- if (creationOrder != 0) return creationOrder;
- return (second.generatedID ?? -1).compareTo(first.generatedID ?? -1);
- });
- const maxFiles = 600;
- const targetFilesPerMemory = 20;
- const maxMemoryGroups = 12;
- final selectedFiles = sortedFiles.take(maxFiles).toList();
- var groupCount =
- (selectedFiles.length + targetFilesPerMemory - 1) ~/
- targetFilesPerMemory;
- if (groupCount > maxMemoryGroups) groupCount = maxMemoryGroups;
-
- final now = DateTime.now().microsecondsSinceEpoch;
- final firstDateToShow = now - const Duration(days: 1).inMicroseconds;
- final lastDateToShow = now + const Duration(days: 1).inMicroseconds;
- final languageCode = (await getLocale())?.languageCode ?? "en";
- final seenTimes = await _memoriesDB.getSeenTimes();
- final filesPerGroup = selectedFiles.length ~/ groupCount;
- final groupsWithExtraFile = selectedFiles.length % groupCount;
- final debugMemories = <SmartMemory>[];
- var offset = 0;
- for (var groupIndex = 0; groupIndex < groupCount; groupIndex++) {
- final groupSize =
- filesPerGroup + (groupIndex < groupsWithExtraFile ? 1 : 0);
- final groupFiles = selectedFiles.sublist(offset, offset + groupSize);
- offset += groupSize;
- final newestCreationTime = groupFiles.first.creationTime!;
- final oldestCreationTime = groupFiles.last.creationTime!;
- final newestDate = SmartMemoriesService.getDateFormatted(
- creationTime: newestCreationTime,
- languageCode: languageCode,
- );
- final oldestDate = SmartMemoriesService.getDateFormatted(
- creationTime: oldestCreationTime,
- languageCode: languageCode,
- );
- final title = oldestDate == newestDate
- ? newestDate
- : "$oldestDate – $newestDate";
- debugMemories.add(
- SmartMemory(
- Memory.fromFiles(groupFiles, seenTimes),
- MemoryType.filler,
- title,
- firstDateToShow,
- lastDateToShow,
- id: "debug-library-$userID-$groupIndex",
- firstCreationTime: oldestCreationTime,
- lastCreationTime: newestCreationTime,
- ),
- );
- }
-
- _debugLibraryMemories = debugMemories;
- _logger.info(
- "TEMP library memories enabled: ${selectedFiles.length} of "
- "${uniqueFiles.length} files across ${debugMemories.length} memories "
- "(${searchFiles.length} search files, "
- "${localOnlyFiles.length} local-only files)",
- );
- return debugMemories;
+ });
}
Future<void> _calculateRegularFillers() async {
diff --git a/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart b/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart
index 2a055f54fb..86ddf1b4d3 100644
--- a/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/custom_listener.dart
@@ -125,24 +125,23 @@ class MemoriesPointerGestureListenerState
_longPressTimer = null;
final wasPartOfMultitouch =
_activePointers.activePointerWasPartOfMultitouch;
- final displacement = _downPosition == null
- ? Offset.zero
- : event.localPosition - _downPosition!;
+ final displacement = event.localPosition - _downPosition!;
final isSwipeUp =
widget.onSwipeUp != null &&
(widget.canSwipeUp?.call() ?? true) &&
!wasPartOfMultitouch &&
displacement.dy <= -widget.swipeUpThreshold &&
- displacement.dy.abs() > displacement.dx.abs();
+ displacement.dy.abs() > displacement.dx.abs() &&
+ displacement.dx.abs() <= widget.touchSlop;
// Release the pointer before callbacks so opening a sheet can take over
// the viewer's pause state without the release immediately resuming it.
_removePointer(event.pointer);
- if (_longPressFired) {
- // widget.onLongPressUp?.call();
- } else if (isSwipeUp) {
+ if (isSwipeUp) {
widget.onSwipeUp?.call();
+ } else if (_longPressFired) {
+ // widget.onLongPressUp?.call();
} else {
if (!wasPartOfMultitouch && !hasPointerMoved) {
widget.onTap?.call(event);
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 2efae00887..458135377c 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -35,6 +35,7 @@ import "package:photos/ui/components/base_bottom_sheet.dart";
import "package:photos/ui/home/memories/custom_listener.dart";
import "package:photos/ui/home/memories/memory_progress_indicator.dart";
import "package:photos/ui/home/memories/memory_video_prefetcher.dart";
+import "package:photos/ui/home/memories/memory_viewer_constants.dart";
import "package:photos/ui/social/widgets/file_social_overlay.dart";
import "package:photos/ui/viewer/file/file_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
@@ -70,9 +71,6 @@ bool _isValidMemoryIndex(int index, int length) {
return index >= 0 && index < length;
}
-const _memoryBottomActionBarHeight = 80.0;
-const _memorySocialScrimHeight = 296.0;
-
class FullScreenMemoryDataUpdater extends StatefulWidget {
final List<Memory> memories;
final int initialIndex;
@@ -406,9 +404,6 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
hasPointerOnScreenNotifier.removeListener(_hasPointerListener);
_detailSheetEventSubscription.cancel();
_socialControlsVisible.dispose();
- _progressAnimationController = null;
- _zoomAnimationController = null;
- _kenBurnsStartToken = null;
super.dispose();
}
@@ -491,9 +486,6 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
if (!mounted) return;
hasFinalFileLoaded = true;
isAtFirstOrLastFile = false;
- if (_progressAnimationController?.isAnimating == true) {
- _progressAnimationController!.stop();
- }
final memoryDuration = Duration(seconds: duration);
_progressAnimationController
?..stop()
@@ -521,7 +513,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
});
} else {
_kenBurnsStartToken = null;
- _zoomAnimationController?.forward();
+ if (!_isAnimationPaused) {
+ _zoomAnimationController?.forward();
+ }
}
}
@@ -535,9 +529,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
)!;
inheritedData.indexNotifier.value = currentIndex;
if (currentIndex < inheritedData.memories.length - 1) {
- inheritedData.indexNotifier.value += 1;
_onPageChange(inheritedData, currentIndex + 1);
} else if (widget.onNextMemory != null) {
+ _resetAnimation();
_setSocialControlsVisible(false);
widget.onNextMemory!();
} else {
@@ -556,9 +550,9 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
)!;
inheritedData.indexNotifier.value = currentIndex;
if (currentIndex > 0) {
- inheritedData.indexNotifier.value -= 1;
_onPageChange(inheritedData, currentIndex - 1);
} else if (widget.onPreviousMemory != null) {
+ _resetAnimation();
_setSocialControlsVisible(false);
widget.onPreviousMemory!();
} else {
@@ -720,6 +714,15 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
_toggleAnimation(pause: !shouldEnable);
},
onFinalFileLoad: ({required int memoryDuration}) {
+ final activeIndex = _clampedMemoryIndex(
+ inheritedData.indexNotifier.value,
+ inheritedData.memories.length,
+ );
+ if (activeIndex == null ||
+ inheritedData.memories[activeIndex].file !=
+ currentFile) {
+ return;
+ }
onFinalFileLoad(memoryDuration);
},
),
@@ -1089,18 +1092,12 @@ class _MemoryTopChrome extends StatelessWidget {
),
if (showFavorite) ...[
const SizedBox(width: 8),
- SizedBox.square(
- dimension: 48,
- child: Center(
- child: FavoriteWidget(
- currentFile,
- iconSize: 24,
- tapTargetSize: 48,
- key: ValueKey(
- currentFile.uploadedFileID ??
- currentFile.localID,
- ),
- ),
+ FavoriteWidget(
+ currentFile,
+ iconSize: 24,
+ tapTargetSize: 48,
+ key: ValueKey(
+ currentFile.uploadedFileID ?? currentFile.localID,
),
),
],
@@ -1183,8 +1180,8 @@ class _MemoryViewerScrims extends StatelessWidget {
curve: Curves.easeOut,
width: double.infinity,
height: isVisible
- ? _memorySocialScrimHeight
- : bottomInset + _memoryBottomActionBarHeight,
+ ? kMemorySocialScrimHeight
+ : bottomInset + kMemoryBottomActionBarHeight,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_progress_indicator.dart b/mobile/apps/photos/lib/ui/home/memories/memory_progress_indicator.dart
index b85d4bf793..1d646383aa 100644
--- a/mobile/apps/photos/lib/ui/home/memories/memory_progress_indicator.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/memory_progress_indicator.dart
@@ -9,13 +9,7 @@ double memoryProgressSegmentWidthForLayout({
required double availableWidth,
double gap = kMemoryProgressGap,
}) {
- if (totalSteps <= 0 ||
- !availableWidth.isFinite ||
- availableWidth <= 0 ||
- !gap.isFinite ||
- gap < 0) {
- return 0;
- }
+ if (totalSteps <= 0) return 0;
final availableSegmentWidth = availableWidth - ((totalSteps - 1) * gap);
if (availableSegmentWidth <= 0) return 0;
diff --git a/mobile/apps/photos/lib/ui/home/memories/memory_viewer_constants.dart b/mobile/apps/photos/lib/ui/home/memories/memory_viewer_constants.dart
new file mode 100644
index 0000000000..fb6be8ff01
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/home/memories/memory_viewer_constants.dart
@@ -0,0 +1,2 @@
+const kMemoryBottomActionBarHeight = 80.0;
+const kMemorySocialScrimHeight = 296.0;
diff --git a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
index 902a467284..c9aa8b0c0b 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
@@ -17,6 +17,7 @@ import "package:photos/models/social/comment_author_utils.dart";
import "package:photos/models/social/reaction.dart";
import "package:photos/models/social/social_data_provider.dart";
import "package:photos/services/collections_service.dart";
+import "package:photos/ui/home/memories/memory_viewer_constants.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
import "package:photos/ui/social/comments_screen.dart";
@@ -28,7 +29,6 @@ final _logger = Logger("FileSocialOverlay");
const _likedColor = Color(0xFF08C225);
const _socialControlsSize = 40.0;
const _socialIconSize = 32.0;
-const _bottomActionBarHeight = 80.0;
const _socialToActionBarGap = 14.0;
class FileSocialOverlay extends StatefulWidget {
@@ -37,7 +37,6 @@ class FileSocialOverlay extends StatefulWidget {
final VoidCallback onInteractionStart;
final VoidCallback onInteractionEnd;
final ValueChanged<bool> onVisibilityChanged;
- final bool includeHiddenCollections;
const FileSocialOverlay({
required this.file,
@@ -45,7 +44,6 @@ class FileSocialOverlay extends StatefulWidget {
required this.onInteractionStart,
required this.onInteractionEnd,
required this.onVisibilityChanged,
- this.includeHiddenCollections = false,
super.key,
});
@@ -63,7 +61,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
Comment? _latestComment;
User? _latestCommentAuthor;
int _loadGeneration = 0;
- int? _reactionUpdateFileID;
+ final _reactionUpdateFileIDs = <int>{};
@override
void initState() {
@@ -78,10 +76,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
void didUpdateWidget(covariant FileSocialOverlay oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.file.uploadedFileID != widget.file.uploadedFileID ||
- oldWidget.currentUserID != widget.currentUserID ||
- oldWidget.includeHiddenCollections != widget.includeHiddenCollections) {
- _loadGeneration++;
- _reactionUpdateFileID = null;
+ oldWidget.currentUserID != widget.currentUserID) {
_clearSocialState();
unawaited(_refreshSocialState());
}
@@ -89,7 +84,6 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
@override
void dispose() {
- _loadGeneration++;
_socialDataUpdatedSubscription.cancel();
super.dispose();
}
@@ -115,15 +109,22 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
if (fileID == null || currentUserID == null) {
_clearSocialState();
+ // Defer because a user-null transition can arrive from didUpdateWidget.
+ scheduleMicrotask(() {
+ if (!mounted ||
+ generation != _loadGeneration ||
+ widget.file.uploadedFileID != fileID ||
+ widget.currentUserID != currentUserID) {
+ return;
+ }
+ widget.onVisibilityChanged(false);
+ });
return;
}
try {
final sharedCollections = await CollectionsService.instance
- .getSharedCollectionsForFile(
- fileID,
- includeHidden: widget.includeHiddenCollections,
- );
+ .getSharedCollectionsForFile(fileID);
if (!_isCurrentLoad(fileID, generation)) return;
if (sharedCollections.isEmpty) {
@@ -167,7 +168,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
setState(() {
_sharedCollections = sharedCollections;
_hasLiked = reactions.any(
- (reaction) => reaction.userID == currentUserID && !reaction.isDeleted,
+ (reaction) => reaction.userID == currentUserID,
);
_commentCount = commentCount;
_latestComment = latestComment;
@@ -175,6 +176,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
});
widget.onVisibilityChanged(true);
} catch (error, stackTrace) {
+ // Preserve last-good state; page changes clear state and visibility.
_logger.warning(
"Failed to refresh social overlay for file $fileID",
error,
@@ -190,11 +192,11 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
if (fileID == null ||
currentUserID == null ||
_sharedCollections.isEmpty ||
- _reactionUpdateFileID == fileID) {
+ _reactionUpdateFileIDs.contains(fileID)) {
return;
}
- _reactionUpdateFileID = fileID;
+ _reactionUpdateFileIDs.add(fileID);
try {
if (_hasLiked) {
await _unlikeFromAllCollections(fileID, currentUserID);
@@ -235,9 +237,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
),
);
} finally {
- if (_reactionUpdateFileID == fileID) {
- _reactionUpdateFileID = null;
- }
+ _reactionUpdateFileIDs.remove(fileID);
}
}
@@ -254,8 +254,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
final reactions = await SocialDataProvider.instance
.getReactionsForFileInCollection(fileID, collection.id);
final userReaction = reactions.firstWhereOrNull(
- (reaction) =>
- reaction.userID == currentUserID && !reaction.isDeleted,
+ (reaction) => reaction.userID == currentUserID,
);
if (userReaction != null) {
await SocialDataProvider.instance.toggleReaction(
@@ -346,7 +345,9 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
return Positioned(
right: safePadding.right + 24,
bottom:
- safePadding.bottom + _bottomActionBarHeight + _socialToActionBarGap,
+ safePadding.bottom +
+ kMemoryBottomActionBarHeight +
+ _socialToActionBarGap,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
@@ -410,9 +411,6 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
}
Widget _buildLatestCommentPill(Comment comment, User author) {
- final currentUserID = widget.currentUserID;
- if (currentUserID == null) return const SizedBox.shrink();
-
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => unawaited(_openComments(comment: comment)),
@@ -462,7 +460,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
child: UserAvatarWidget(
author,
type: AvatarType.small,
- currentUserID: currentUserID,
+ currentUserID: widget.currentUserID!,
),
),
),
diff --git a/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart b/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart
index 15654bb11f..c9f9823ff1 100644
--- a/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart
+++ b/mobile/apps/photos/test/ui/home/memories/custom_listener_test.dart
@@ -36,6 +36,33 @@ void main() {
expect(swipeCount, 1);
});
+ testWidgets("opens details when an upward swipe follows a hold", (
+ tester,
+ ) async {
+ var swipeCount = 0;
+ await pumpListener(tester, onSwipeUp: () => swipeCount++);
+ final gesture = await tester.startGesture(
+ tester.getCenter(find.byKey(targetKey)),
+ );
+
+ await tester.pump(const Duration(milliseconds: 600));
+ await gesture.moveBy(const Offset(0, -60));
+ await gesture.up();
+
+ expect(swipeCount, 1);
+ });
+
+ testWidgets("does not open details after horizontal page displacement", (
+ tester,
+ ) async {
+ var swipeCount = 0;
+ await pumpListener(tester, onSwipeUp: () => swipeCount++);
+
+ await tester.drag(find.byKey(targetKey), const Offset(20, -60));
+
+ expect(swipeCount, 0);
+ });
+
testWidgets("does not open details while media is zoomed", (tester) async {
var swipeCount = 0;
await pumpListener(