0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-07 00:50:23 -05:00

feat(mobile): pinch to zoom on asset grid (#2905)

This commit is contained in:
Fynn Petersen-Frey 2023-06-22 04:13:23 +02:00 committed by GitHub
parent 2c924e4c1c
commit 7f44d508dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,6 @@
import 'dart:math';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
@ -51,6 +54,12 @@ class ImmichAssetGrid extends HookConsumerWidget {
final enableHeroAnimations = useState(false); final enableHeroAnimations = useState(false);
final transitionDuration = ModalRoute.of(context)?.transitionDuration; final transitionDuration = ModalRoute.of(context)?.transitionDuration;
final perRow = useState(
assetsPerRow ?? settings.getSetting(AppSettingsEnum.tilesPerRow)!,
);
final scaleFactor = useState(7.0 - perRow.value);
final baseScaleFactor = useState(7.0 - perRow.value);
useEffect( useEffect(
() { () {
// Wait for transition to complete, then re-enable // Wait for transition to complete, then re-enable
@ -80,10 +89,30 @@ class ImmichAssetGrid extends HookConsumerWidget {
onWillPop: onWillPop, onWillPop: onWillPop,
child: HeroMode( child: HeroMode(
enabled: enableHeroAnimations.value, enabled: enableHeroAnimations.value,
child: RawGestureDetector(
gestures: {
CustomScaleGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
CustomScaleGestureRecognizer>(
() => CustomScaleGestureRecognizer(),
(CustomScaleGestureRecognizer scale) {
scale.onStart = (details) {
baseScaleFactor.value = scaleFactor.value;
};
scale.onUpdate = (details) {
scaleFactor.value =
max(min(5.0, baseScaleFactor.value * details.scale), 1.0);
if (7 - scaleFactor.value.toInt() != perRow.value) {
perRow.value = 7 - scaleFactor.value.toInt();
}
};
scale.onEnd = (details) {};
})
},
child: ImmichAssetGridView( child: ImmichAssetGridView(
onRefresh: onRefresh, onRefresh: onRefresh,
assetsPerRow: assetsPerRow ?? assetsPerRow: perRow.value,
settings.getSetting(AppSettingsEnum.tilesPerRow),
listener: listener, listener: listener,
showStorageIndicator: showStorageIndicator ?? showStorageIndicator: showStorageIndicator ??
settings.getSetting(AppSettingsEnum.storageIndicator), settings.getSetting(AppSettingsEnum.storageIndicator),
@ -98,6 +127,7 @@ class ImmichAssetGrid extends HookConsumerWidget {
visibleItemsListener: visibleItemsListener, visibleItemsListener: visibleItemsListener,
), ),
), ),
),
); );
} }
@ -113,3 +143,11 @@ class ImmichAssetGrid extends HookConsumerWidget {
); );
} }
} }
/// accepts a gesture even though it should reject it (because child won)
class CustomScaleGestureRecognizer extends ScaleGestureRecognizer {
@override
void rejectGesture(int pointer) {
acceptGesture(pointer);
}
}