1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00

fix(mobile): Fixes hero animation on main timeline (#1924)

* fixed hero animation for local assets

* fixes backwards hero animation out of gallery image
This commit is contained in:
martyfuhry 2023-03-03 17:49:40 -05:00 committed by GitHub
parent a5f49b065c
commit dac4020f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 7 deletions

View File

@ -123,7 +123,10 @@ class GalleryViewerPage extends HookConsumerWidget {
/// Original (large) image of a local asset. Required asset.isLocal /// Original (large) image of a local asset. Required asset.isLocal
ImageProvider localImageProvider(Asset asset) { ImageProvider localImageProvider(Asset asset) {
return AssetEntityImageProvider(asset.local!); return AssetEntityImageProvider(
isOriginal: true,
asset.local!,
);
} }
void precacheNextImage(int index) { void precacheNextImage(int index) {
@ -385,8 +388,11 @@ class GalleryViewerPage extends HookConsumerWidget {
onTapDown: (_, __, ___) => onTapDown: (_, __, ___) =>
showAppBar.value = !showAppBar.value, showAppBar.value = !showAppBar.value,
imageProvider: provider, imageProvider: provider,
heroAttributes: heroAttributes: PhotoViewHeroAttributes(
PhotoViewHeroAttributes(tag: assetList[index].id), tag: assetList[index].id,
),
filterQuality: FilterQuality.high,
tightMode: true,
minScale: PhotoViewComputedScale.contained, minScale: PhotoViewComputedScale.contained,
); );
} else { } else {
@ -394,8 +400,10 @@ class GalleryViewerPage extends HookConsumerWidget {
onDragStart: (_, details, __) => onDragStart: (_, details, __) =>
localPosition = details.localPosition, localPosition = details.localPosition,
onDragUpdate: (_, details, __) => handleSwipeUpDown(details), onDragUpdate: (_, details, __) => handleSwipeUpDown(details),
heroAttributes: heroAttributes: PhotoViewHeroAttributes(
PhotoViewHeroAttributes(tag: assetList[index].id), tag: assetList[index].id,
),
filterQuality: FilterQuality.high,
maxScale: 1.0, maxScale: 1.0,
minScale: 1.0, minScale: 1.0,
child: SafeArea( child: SafeArea(

View File

@ -67,6 +67,31 @@ class ThumbnailImage extends HookConsumerWidget {
HapticFeedback.heavyImpact(); HapticFeedback.heavyImpact();
}, },
child: Hero( child: Hero(
createRectTween: (begin, end) {
double? top;
// Uses the [BoxFit.contain] algorithm
if (asset.width != null && asset.height != null) {
final assetAR = asset.width! / asset.height!;
final w = MediaQuery.of(context).size.width;
final deviceAR = MediaQuery.of(context).size.aspectRatio;
if (deviceAR < assetAR) {
top = asset.height! * w / asset.width!;
} else {
top = 0;
}
// get the height offset
}
return MaterialRectCenterArcTween(
begin: Rect.fromLTRB(
0,
top ?? 0.0,
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height,
),
end: end,
);
},
tag: asset.id, tag: asset.id,
child: Stack( child: Stack(
children: [ children: [

View File

@ -259,7 +259,6 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
controller: pageOption.controller, controller: pageOption.controller,
scaleStateController: pageOption.scaleStateController, scaleStateController: pageOption.scaleStateController,
customSize: widget.customSize, customSize: widget.customSize,
heroAttributes: pageOption.heroAttributes,
scaleStateChangedCallback: scaleStateChangedCallback, scaleStateChangedCallback: scaleStateChangedCallback,
enableRotation: widget.enableRotation, enableRotation: widget.enableRotation,
initialScale: pageOption.initialScale, initialScale: pageOption.initialScale,
@ -289,7 +288,6 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
scaleStateController: pageOption.scaleStateController, scaleStateController: pageOption.scaleStateController,
customSize: widget.customSize, customSize: widget.customSize,
gaplessPlayback: widget.gaplessPlayback, gaplessPlayback: widget.gaplessPlayback,
heroAttributes: pageOption.heroAttributes,
scaleStateChangedCallback: scaleStateChangedCallback, scaleStateChangedCallback: scaleStateChangedCallback,
enableRotation: widget.enableRotation, enableRotation: widget.enableRotation,
initialScale: pageOption.initialScale, initialScale: pageOption.initialScale,
@ -310,6 +308,19 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
errorBuilder: pageOption.errorBuilder, errorBuilder: pageOption.errorBuilder,
); );
if (pageOption.heroAttributes != null) {
return Hero(
tag: pageOption.heroAttributes!.tag,
createRectTween: pageOption.heroAttributes!.createRectTween,
flightShuttleBuilder: pageOption.heroAttributes!.flightShuttleBuilder,
placeholderBuilder: pageOption.heroAttributes!.placeholderBuilder,
transitionOnUserGestures: pageOption.heroAttributes!.transitionOnUserGestures,
child: ClipRect(
child: photoView,
),
);
}
return ClipRect( return ClipRect(
child: photoView, child: photoView,
); );