[mobile][photos] Fix missing hero animation (#1064)

## Description

Sometimes, when opening an image from gallery, the hero animation fails
to happen. This PR fixes this issue.



https://github.com/ente-io/ente/assets/77285023/2ee40ec8-58d0-4ca1-82fb-1be96581137b



## Tests

- [x] Didn't break hero animations of videos, it almost stays the same.
This commit is contained in:
Ashil 2024-03-13 11:20:20 +05:30 committed by GitHub
parent 96bb79b9e9
commit 773f4cdca2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View file

@ -104,6 +104,40 @@ class _ZoomableImageState extends State<ZoomableImage> {
tag: widget.tagPrefix! + _photo.tag,
),
backgroundDecoration: widget.backgroundDecoration as BoxDecoration?,
loadingBuilder: (context, event) {
// This is to make sure the hero anitmation animates and fits in the
//dimensions of the image on screen.
final screenDimensions = MediaQuery.sizeOf(context);
late final double screenRelativeImageWidth;
late final double screenRelativeImageHeight;
final screenWidth = screenDimensions.width;
final screenHeight = screenDimensions.height;
final aspectRatioOfScreen = screenWidth / screenHeight;
final aspectRatioOfImage = _photo.width / _photo.height;
if (aspectRatioOfImage > aspectRatioOfScreen) {
screenRelativeImageWidth = screenWidth;
screenRelativeImageHeight = screenWidth / aspectRatioOfImage;
} else if (aspectRatioOfImage < aspectRatioOfScreen) {
screenRelativeImageHeight = screenHeight;
screenRelativeImageWidth = screenHeight * aspectRatioOfImage;
} else {
screenRelativeImageWidth = screenWidth;
screenRelativeImageHeight = screenHeight;
}
return Center(
child: SizedBox(
width: screenRelativeImageWidth,
height: screenRelativeImageHeight,
child: Hero(
tag: widget.tagPrefix! + _photo.tag,
child: const EnteLoadingWidget(),
),
),
);
},
),
);
} else {

View file

@ -73,6 +73,14 @@ class GalleryFileWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(1),
child: Hero(
tag: heroTag,
flightShuttleBuilder: (
flightContext,
animation,
flightDirection,
fromHeroContext,
toHeroContext,
) =>
thumbnailWidget,
transitionOnUserGestures: true,
child: isFileSelected
? ColorFiltered(