feat(mobile): play motion video with long press gesture support (#6543)

This commit is contained in:
jzhangdev
2024-05-02 23:37:39 +08:00
committed by GitHub
parent 9bce3417e9
commit 42f03af2dc
6 changed files with 52 additions and 0 deletions
@@ -9,6 +9,7 @@ import 'package:immich_mobile/shared/ui/photo_view/photo_view.dart'
PhotoViewImageDragEndCallback,
PhotoViewImageDragStartCallback,
PhotoViewImageDragUpdateCallback,
PhotoViewImageLongPressStartCallback,
ScaleStateCycle;
import 'package:immich_mobile/shared/ui/photo_view/src/controller/photo_view_controller.dart';
import 'package:immich_mobile/shared/ui/photo_view/src/controller/photo_view_controller_delegate.dart';
@@ -37,6 +38,7 @@ class PhotoViewCore extends StatefulWidget {
required this.onDragEnd,
required this.onDragUpdate,
required this.onScaleEnd,
required this.onLongPressStart,
required this.gestureDetectorBehavior,
required this.controller,
required this.scaleBoundaries,
@@ -61,6 +63,7 @@ class PhotoViewCore extends StatefulWidget {
this.onDragEnd,
this.onDragUpdate,
this.onScaleEnd,
this.onLongPressStart,
this.gestureDetectorBehavior,
required this.controller,
required this.scaleBoundaries,
@@ -95,6 +98,8 @@ class PhotoViewCore extends StatefulWidget {
final PhotoViewImageDragEndCallback? onDragEnd;
final PhotoViewImageDragUpdateCallback? onDragUpdate;
final PhotoViewImageLongPressStartCallback? onLongPressStart;
final HitTestBehavior? gestureDetectorBehavior;
final bool tightMode;
final bool disableGestures;
@@ -373,6 +378,9 @@ class PhotoViewCoreState extends State<PhotoViewCore>
onTapDown: widget.onTapDown != null
? (details) => widget.onTapDown!(context, details, value)
: null,
onLongPressStart: widget.onLongPressStart != null
? (details) => widget.onLongPressStart!(context, details, value)
: null,
child: child,
);
} else {
@@ -16,6 +16,7 @@ class PhotoViewGestureDetector extends StatelessWidget {
this.onDragStart,
this.onDragEnd,
this.onDragUpdate,
this.onLongPressStart,
this.child,
this.onTapUp,
this.onTapDown,
@@ -36,6 +37,8 @@ class PhotoViewGestureDetector extends StatelessWidget {
final GestureTapUpCallback? onTapUp;
final GestureTapDownCallback? onTapDown;
final GestureLongPressStartCallback? onLongPressStart;
final Widget? child;
final HitTestBehavior? behavior;
@@ -99,6 +102,13 @@ class PhotoViewGestureDetector extends StatelessWidget {
},
);
gestures[LongPressGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
() => LongPressGestureRecognizer(debugOwner: this),
(LongPressGestureRecognizer instance) {
instance.onLongPressStart = onLongPressStart;
});
return RawGestureDetector(
behavior: behavior,
gestures: gestures,
@@ -28,6 +28,7 @@ class ImageWrapper extends StatefulWidget {
required this.onDragEnd,
required this.onDragUpdate,
required this.onScaleEnd,
required this.onLongPressStart,
required this.outerSize,
required this.gestureDetectorBehavior,
required this.tightMode,
@@ -59,6 +60,7 @@ class ImageWrapper extends StatefulWidget {
final PhotoViewImageDragEndCallback? onDragEnd;
final PhotoViewImageDragUpdateCallback? onDragUpdate;
final PhotoViewImageScaleEndCallback? onScaleEnd;
final PhotoViewImageLongPressStartCallback? onLongPressStart;
final Size outerSize;
final HitTestBehavior? gestureDetectorBehavior;
final bool? tightMode;
@@ -205,6 +207,7 @@ class _ImageWrapperState extends State<ImageWrapper> {
onDragEnd: widget.onDragEnd,
onDragUpdate: widget.onDragUpdate,
onScaleEnd: widget.onScaleEnd,
onLongPressStart: widget.onLongPressStart,
gestureDetectorBehavior: widget.gestureDetectorBehavior,
tightMode: widget.tightMode ?? false,
filterQuality: widget.filterQuality ?? FilterQuality.none,
@@ -257,6 +260,7 @@ class CustomChildWrapper extends StatelessWidget {
this.onDragEnd,
this.onDragUpdate,
this.onScaleEnd,
this.onLongPressStart,
required this.outerSize,
this.gestureDetectorBehavior,
required this.tightMode,
@@ -287,6 +291,7 @@ class CustomChildWrapper extends StatelessWidget {
final PhotoViewImageDragEndCallback? onDragEnd;
final PhotoViewImageDragUpdateCallback? onDragUpdate;
final PhotoViewImageScaleEndCallback? onScaleEnd;
final PhotoViewImageLongPressStartCallback? onLongPressStart;
final Size outerSize;
final HitTestBehavior? gestureDetectorBehavior;
final bool? tightMode;
@@ -320,6 +325,7 @@ class CustomChildWrapper extends StatelessWidget {
onDragEnd: onDragEnd,
onDragUpdate: onDragUpdate,
onScaleEnd: onScaleEnd,
onLongPressStart: onLongPressStart,
gestureDetectorBehavior: gestureDetectorBehavior,
tightMode: tightMode ?? false,
filterQuality: filterQuality ?? FilterQuality.none,