Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add hero transitions for feed item image opens

ashilkn091ede34e7df
diff --git a/mobile/apps/photos/lib/ui/social/feed_screen.dart b/mobile/apps/photos/lib/ui/social/feed_screen.dart
index 46678deb8c..d2504f7c88 100644
--- a/mobile/apps/photos/lib/ui/social/feed_screen.dart
+++ b/mobile/apps/photos/lib/ui/social/feed_screen.dart
@@ -557,22 +557,27 @@ class _FeedScreenState extends State<FeedScreen> {
}
final item = _feedItems[index];
final isLastItem = index == _feedItems.length - 1;
+ final itemKey = _feedItemStableKey(item);
+ final heroTagPrefix = _heroTagPrefixForFeedItem(item);
final key = _shouldUseNavigationTargetKey(item)
? _navigationTargetItemKey
- : ValueKey(
- '${item.type}_${item.fileID}_${item.commentID}_${item.createdAt}',
- );
+ : ValueKey(itemKey);
return FeedItemWidget(
key: key,
feedItem: item,
+ heroTagPrefix: heroTagPrefix,
currentUserID: _currentUserID,
anonDisplayNames:
_anonDisplayNamesByCollection[item.collectionID] ??
const {},
isLastItem: isLastItem,
- onTap: () => _handleFeedItemTap(item),
+ onTap: () => _handleFeedItemTap(
+ item,
+ heroTagPrefix: heroTagPrefix,
+ ),
onSharedHeaderTap: () => _openSharedCollection(
item,
+ heroTagPrefix: heroTagPrefix,
jumpToFileID: _jumpFileIDForSharedCollection(
type: item.type,
sharedFileIDs: item.sharedFileIDs,
@@ -581,6 +586,7 @@ class _FeedScreenState extends State<FeedScreen> {
onSharedPhotoTap: (fileID) => _openSharedPhotos(
item,
initialFileID: fileID,
+ heroTagPrefix: heroTagPrefix,
),
);
},
@@ -618,22 +624,30 @@ class _FeedScreenState extends State<FeedScreen> {
);
}
- void _handleFeedItemTap(FeedItem item) {
+ String _feedItemStableKey(FeedItem item) {
+ return '${item.type}_${item.fileID}_${item.commentID}_${item.createdAt}';
+ }
+
+ String _heroTagPrefixForFeedItem(FeedItem item) {
+ return 'feed_item_${_feedItemStableKey(item)}_';
+ }
+
+ void _handleFeedItemTap(FeedItem item, {required String heroTagPrefix}) {
switch (item.type) {
case FeedItemType.photoLike:
- _openPhoto(item);
+ _openPhoto(item, heroTagPrefix: heroTagPrefix);
break;
case FeedItemType.sharedPhoto:
- _openSharedPhotos(item);
+ _openSharedPhotos(item, heroTagPrefix: heroTagPrefix);
break;
case FeedItemType.sharedCollection:
- _openSharedCollection(item);
+ _openSharedCollection(item, heroTagPrefix: heroTagPrefix);
break;
case FeedItemType.comment:
case FeedItemType.reply:
case FeedItemType.commentLike:
case FeedItemType.replyLike:
- _openComments(item);
+ _openComments(item, heroTagPrefix: heroTagPrefix);
break;
}
}
@@ -641,6 +655,7 @@ class _FeedScreenState extends State<FeedScreen> {
Future<void> _openSharedCollection(
FeedItem item, {
int? jumpToFileID,
+ String? heroTagPrefix,
}) async {
var collection = CollectionsService.instance.getCollectionByID(
item.collectionID,
@@ -661,7 +676,11 @@ class _FeedScreenState extends State<FeedScreen> {
if (collection == null || !mounted) {
// Fallback to shared-photos viewer if collection metadata isn't available.
- await _openSharedPhotos(item, initialFileID: jumpToFileID);
+ await _openSharedPhotos(
+ item,
+ initialFileID: jumpToFileID,
+ heroTagPrefix: heroTagPrefix,
+ );
return;
}
@@ -704,7 +723,7 @@ class _FeedScreenState extends State<FeedScreen> {
}
/// Opens the photo viewer for the feed item, then shows the comments sheet.
- Future<void> _openComments(FeedItem item) async {
+ Future<void> _openComments(FeedItem item, {String? heroTagPrefix}) async {
var fileID = item.fileID;
if (fileID == null && item.commentID != null) {
@@ -731,7 +750,7 @@ class _FeedScreenState extends State<FeedScreen> {
DetailPageConfiguration(
[file],
0,
- "feed_comment",
+ heroTagPrefix ?? "feed_comment",
onPageReady: (detailContext) {
showFileCommentsBottomSheet(
detailContext,
@@ -748,7 +767,7 @@ class _FeedScreenState extends State<FeedScreen> {
}
/// Opens the photo viewer for the feed item.
- Future<void> _openPhoto(FeedItem item) async {
+ Future<void> _openPhoto(FeedItem item, {String? heroTagPrefix}) async {
var fileID = item.fileID;
if (fileID == null && item.commentID != null) {
@@ -772,7 +791,7 @@ class _FeedScreenState extends State<FeedScreen> {
DetailPageConfiguration(
[file],
0,
- "feed_item",
+ heroTagPrefix ?? "feed_item",
),
),
forceCustomPageRoute: true,
@@ -781,7 +800,11 @@ class _FeedScreenState extends State<FeedScreen> {
}
/// Opens a gallery view of the shared photos.
- Future<void> _openSharedPhotos(FeedItem item, {int? initialFileID}) async {
+ Future<void> _openSharedPhotos(
+ FeedItem item, {
+ int? initialFileID,
+ String? heroTagPrefix,
+ }) async {
final fileIDs = item.sharedFileIDs;
if (fileIDs == null || fileIDs.isEmpty) return;
@@ -810,7 +833,7 @@ class _FeedScreenState extends State<FeedScreen> {
DetailPageConfiguration(
files,
initialIndex,
- "feed_shared_photos",
+ heroTagPrefix ?? "feed_shared_photos",
),
),
forceCustomPageRoute: true,
diff --git a/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart
index cfa00f5217..64905d3d06 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/feed_item_widget.dart
@@ -17,6 +17,7 @@ import "package:photos/ui/viewer/file/thumbnail_widget.dart";
/// Widget that displays a single feed item.
class FeedItemWidget extends StatelessWidget {
final FeedItem feedItem;
+ final String heroTagPrefix;
final int currentUserID;
/// Called when the user taps anywhere on the feed item.
@@ -36,6 +37,7 @@ class FeedItemWidget extends StatelessWidget {
const FeedItemWidget({
required this.feedItem,
+ required this.heroTagPrefix,
required this.currentUserID,
this.onTap,
this.onSharedPhotoTap,
@@ -113,6 +115,7 @@ class FeedItemWidget extends StatelessWidget {
child: _FeedThumbnail(
fileID: feedItem.fileID!,
collectionID: feedItem.collectionID,
+ heroTagPrefix: heroTagPrefix,
),
)
else
@@ -189,6 +192,7 @@ class FeedItemWidget extends StatelessWidget {
child: SharedPhotosGrid(
fileIDs: feedItem.sharedFileIDs!,
collectionID: feedItem.collectionID,
+ heroTagPrefix: heroTagPrefix,
onTap: onTap,
onPhotoTap: onSharedPhotoTap,
),
@@ -665,10 +669,12 @@ class _FeedTextContent extends StatelessWidget {
class _FeedThumbnail extends StatefulWidget {
final int fileID;
final int collectionID;
+ final String heroTagPrefix;
const _FeedThumbnail({
required this.fileID,
required this.collectionID,
+ required this.heroTagPrefix,
});
@override
@@ -739,20 +745,23 @@ class _FeedThumbnailState extends State<_FeedThumbnail> {
);
}
- return Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(9),
- border: Border.all(color: colorScheme.strokeFaint),
- ),
- child: ClipRRect(
- borderRadius: BorderRadius.circular(8),
- child: SizedBox(
- width: 66,
- height: 66,
- child: ThumbnailWidget(
- _file!,
- fit: BoxFit.cover,
- rawThumbnail: true,
+ return Hero(
+ tag: widget.heroTagPrefix + _file!.tag,
+ child: Container(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(9),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(8),
+ child: SizedBox(
+ width: 66,
+ height: 66,
+ child: ThumbnailWidget(
+ _file!,
+ fit: BoxFit.cover,
+ rawThumbnail: true,
+ ),
),
),
),
diff --git a/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart
index 1af05c915d..66b54ba137 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/shared_photos_grid.dart
@@ -26,12 +26,16 @@ class SharedPhotosGrid extends StatefulWidget {
/// Called when user taps an individual photo thumbnail.
final ValueChanged<int>? onPhotoTap;
+ /// Prefix used for Hero tags while opening shared photos.
+ final String heroTagPrefix;
+
/// Size of the grid (width). Height is calculated based on layout.
final double gridSize;
const SharedPhotosGrid({
required this.fileIDs,
required this.collectionID,
+ required this.heroTagPrefix,
this.onTap,
this.onPhotoTap,
this.gridSize = 300,
@@ -258,15 +262,18 @@ class _SharedPhotosGridState extends State<SharedPhotosGrid> {
}
Widget _buildSharedPhotoThumbnail(EnteFile file) {
- final thumbnail = ThumbnailWidget(
- file,
- fit: BoxFit.cover,
- rawThumbnail: false,
- shouldShowFavoriteIcon: false,
- shouldShowSyncStatus: false,
- shouldShowLivePhotoOverlay: true,
- thumbnailSize: thumbnailLargeSize,
- useRequestedThumbnailSizeForLocalCache: true,
+ final thumbnail = Hero(
+ tag: widget.heroTagPrefix + file.tag,
+ child: ThumbnailWidget(
+ file,
+ fit: BoxFit.cover,
+ rawThumbnail: false,
+ shouldShowFavoriteIcon: false,
+ shouldShowSyncStatus: false,
+ shouldShowLivePhotoOverlay: true,
+ thumbnailSize: thumbnailLargeSize,
+ useRequestedThumbnailSizeForLocalCache: true,
+ ),
);
final fileID = file.uploadedFileID;
if (widget.onPhotoTap == null || fileID == null) {