1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-04 02:46:47 +01:00

feat(mobile): reduce UI rebuilds (#3129)

This commit is contained in:
Fynn Petersen-Frey 2023-07-08 15:46:22 +02:00 committed by GitHub
parent 50c7b35291
commit fe2330ebf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,51 +50,17 @@ class ImmichAssetGrid extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
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 settings = ref.watch(appSettingsServiceProvider);
final perRow = useState(
assetsPerRow ?? settings.getSetting(AppSettingsEnum.tilesPerRow)!,
);
final scaleFactor = 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) {
return WillPopScope(
onWillPop: onWillPop,
child: HeroMode(
enabled: enableHeroAnimations.value,
child: RawGestureDetector(
return RawGestureDetector(
gestures: {
CustomScaleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
CustomScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers<
CustomScaleGestureRecognizer>(
() => CustomScaleGestureRecognizer(),
(CustomScaleGestureRecognizer scale) {
@ -109,7 +75,6 @@ class ImmichAssetGrid extends HookConsumerWidget {
perRow.value = 7 - scaleFactor.value.toInt();
}
};
scale.onEnd = (details) {};
})
},
child: ImmichAssetGridView(
@ -129,8 +94,6 @@ class ImmichAssetGrid extends HookConsumerWidget {
visibleItemsListener: visibleItemsListener,
topWidget: topWidget,
),
),
),
);
}