1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +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,49 +50,86 @@ 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);
Widget buildAssetGridView(RenderList renderList) { useEffect(
return RawGestureDetector( () {
gestures: { // Wait for transition to complete, then re-enable
CustomScaleGestureRecognizer: GestureRecognizerFactoryWithHandlers< if (transitionDuration == null) {
CustomScaleGestureRecognizer>( // No route transition found, maybe we opened this up first
() => CustomScaleGestureRecognizer(), enableHeroAnimations.value = true;
(CustomScaleGestureRecognizer scale) { } else {
scale.onStart = (details) { // Unfortunately, using the transition animation itself didn't
baseScaleFactor.value = scaleFactor.value; // 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;
},
[],
);
scale.onUpdate = (details) { Future<bool> onWillPop() async {
scaleFactor.value = enableHeroAnimations.value = false;
max(min(5.0, baseScaleFactor.value * details.scale), 1.0); return true;
if (7 - scaleFactor.value.toInt() != perRow.value) { }
perRow.value = 7 - scaleFactor.value.toInt();
} Widget buildAssetGridView(RenderList renderList) {
}; return WillPopScope(
}) onWillPop: onWillPop,
}, child: HeroMode(
child: ImmichAssetGridView( enabled: enableHeroAnimations.value,
onRefresh: onRefresh, child: RawGestureDetector(
assetsPerRow: perRow.value, gestures: {
listener: listener, CustomScaleGestureRecognizer:
showStorageIndicator: showStorageIndicator ?? GestureRecognizerFactoryWithHandlers<
settings.getSetting(AppSettingsEnum.storageIndicator), CustomScaleGestureRecognizer>(
renderList: renderList, () => CustomScaleGestureRecognizer(),
margin: margin, (CustomScaleGestureRecognizer scale) {
selectionActive: selectionActive, scale.onStart = (details) {
preselectedAssets: preselectedAssets, baseScaleFactor.value = scaleFactor.value;
canDeselect: canDeselect, };
dynamicLayout: dynamicLayout ??
settings.getSetting(AppSettingsEnum.dynamicLayout), scale.onUpdate = (details) {
showMultiSelectIndicator: showMultiSelectIndicator, scaleFactor.value =
visibleItemsListener: visibleItemsListener, max(min(5.0, baseScaleFactor.value * details.scale), 1.0);
topWidget: topWidget, if (7 - scaleFactor.value.toInt() != perRow.value) {
perRow.value = 7 - scaleFactor.value.toInt();
}
};
scale.onEnd = (details) {};
})
},
child: ImmichAssetGridView(
onRefresh: onRefresh,
assetsPerRow: perRow.value,
listener: listener,
showStorageIndicator: showStorageIndicator ??
settings.getSetting(AppSettingsEnum.storageIndicator),
renderList: renderList,
margin: margin,
selectionActive: selectionActive,
preselectedAssets: preselectedAssets,
canDeselect: canDeselect,
dynamicLayout: dynamicLayout ??
settings.getSetting(AppSettingsEnum.dynamicLayout),
showMultiSelectIndicator: showMultiSelectIndicator,
visibleItemsListener: visibleItemsListener,
topWidget: topWidget,
),
),
), ),
); );
} }