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

Revert "feat(mobile): reduce UI rebuilds (#3129)" (#3159)

This reverts commit fe2330ebf6.
This commit is contained in:
Fynn Petersen-Frey 2023-07-08 22:03:54 +02:00 committed by GitHub
parent b262bcec03
commit d590dec159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,17 +50,51 @@ class ImmichAssetGrid extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final settings = ref.watch(appSettingsServiceProvider); var settings = ref.watch(appSettingsServiceProvider);
// Needs to suppress hero animations when navigating to this widget
final enableHeroAnimations = useState(false);
final transitionDuration = ModalRoute.of(context)?.transitionDuration;
final perRow = useState( final perRow = useState(
assetsPerRow ?? settings.getSetting(AppSettingsEnum.tilesPerRow)!, assetsPerRow ?? settings.getSetting(AppSettingsEnum.tilesPerRow)!,
); );
final scaleFactor = useState(7.0 - perRow.value); final scaleFactor = useState(7.0 - perRow.value);
final baseScaleFactor = useState(7.0 - perRow.value); final baseScaleFactor = useState(7.0 - perRow.value);
useEffect(
() {
// Wait for transition to complete, then re-enable
if (transitionDuration == null) {
// No route transition found, maybe we opened this up first
enableHeroAnimations.value = true;
} else {
// Unfortunately, using the transition animation itself didn't
// seem to work reliably. So instead, wait until the duration of the
// animation has elapsed to re-enable the hero animations
Future.delayed(transitionDuration).then((_) {
enableHeroAnimations.value = true;
});
}
return null;
},
[],
);
Future<bool> onWillPop() async {
enableHeroAnimations.value = false;
return true;
}
Widget buildAssetGridView(RenderList renderList) { Widget buildAssetGridView(RenderList renderList) {
return RawGestureDetector( return WillPopScope(
onWillPop: onWillPop,
child: HeroMode(
enabled: enableHeroAnimations.value,
child: RawGestureDetector(
gestures: { gestures: {
CustomScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers< CustomScaleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
CustomScaleGestureRecognizer>( CustomScaleGestureRecognizer>(
() => CustomScaleGestureRecognizer(), () => CustomScaleGestureRecognizer(),
(CustomScaleGestureRecognizer scale) { (CustomScaleGestureRecognizer scale) {
@ -75,6 +109,7 @@ class ImmichAssetGrid extends HookConsumerWidget {
perRow.value = 7 - scaleFactor.value.toInt(); perRow.value = 7 - scaleFactor.value.toInt();
} }
}; };
scale.onEnd = (details) {};
}) })
}, },
child: ImmichAssetGridView( child: ImmichAssetGridView(
@ -94,6 +129,8 @@ class ImmichAssetGrid extends HookConsumerWidget {
visibleItemsListener: visibleItemsListener, visibleItemsListener: visibleItemsListener,
topWidget: topWidget, topWidget: topWidget,
), ),
),
),
); );
} }