Skip to content

Commit

Permalink
separate double tap and tap drag zoom options
Browse files Browse the repository at this point in the history
  • Loading branch information
NANI-SORE committed Nov 20, 2023
1 parent 233a392 commit 4b71f49
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/photo_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class PhotoView extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
this.customSize,
Expand Down Expand Up @@ -294,6 +295,7 @@ class PhotoView extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
this.customSize,
Expand Down Expand Up @@ -398,6 +400,8 @@ class PhotoView extends StatefulWidget {
/// particular location.
final PhotoViewImageScaleEndCallback? onScaleEnd;

final bool? enableDoubleTapZoom;

final bool? enableTapDragZoom;

final PhotoViewDoubleTapZoomEndCallback? onDoubleTapZoomEnd;
Expand Down Expand Up @@ -537,6 +541,7 @@ class _PhotoViewState extends State<PhotoView>
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
onScaleEnd: widget.onScaleEnd,
enableDoubleTapZoom: widget.enableDoubleTapZoom,
onDoubleTapZoomEnd: widget.onDoubleTapZoomEnd,
enableTapDragZoom: widget.enableTapDragZoom,
outerSize: computedOuterSize,
Expand Down Expand Up @@ -566,6 +571,7 @@ class _PhotoViewState extends State<PhotoView>
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
onScaleEnd: widget.onScaleEnd,
enableDoubleTapZoom: widget.enableDoubleTapZoom,
onDoubleTapZoomEnd: widget.onDoubleTapZoomEnd,
enableTapDragZoom: widget.enableTapDragZoom,
outerSize: computedOuterSize,
Expand Down
6 changes: 6 additions & 0 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
onTapUp: pageOption.onTapUp,
onTapDown: pageOption.onTapDown,
onScaleEnd: pageOption.onScaleEnd,
enableDoubleTapZoom: pageOption.enableDoubleTapZoom,
onDoubleTapZoomEnd: pageOption.onDoubleTapZoomEnd,
enableTapDragZoom: pageOption.enableTapDragZoom,
gestureDetectorBehavior: pageOption.gestureDetectorBehavior,
Expand Down Expand Up @@ -301,6 +302,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
onTapUp: pageOption.onTapUp,
onTapDown: pageOption.onTapDown,
onScaleEnd: pageOption.onScaleEnd,
enableDoubleTapZoom: pageOption.enableDoubleTapZoom,
onDoubleTapZoomEnd: pageOption.onDoubleTapZoomEnd,
enableTapDragZoom: pageOption.enableTapDragZoom,
gestureDetectorBehavior: pageOption.gestureDetectorBehavior,
Expand Down Expand Up @@ -345,6 +347,7 @@ class PhotoViewGalleryPageOptions {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
this.gestureDetectorBehavior,
Expand All @@ -371,6 +374,7 @@ class PhotoViewGalleryPageOptions {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
this.gestureDetectorBehavior,
Expand Down Expand Up @@ -425,6 +429,8 @@ class PhotoViewGalleryPageOptions {
/// Mirror to [PhotoView.onScaleEnd]
final PhotoViewImageScaleEndCallback? onScaleEnd;

final bool? enableDoubleTapZoom;

final bool? enableTapDragZoom;

/// Mirror to [PhotoView.onDoubleTapZoomEnd]
Expand Down
8 changes: 7 additions & 1 deletion lib/src/core/photo_view_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PhotoViewCore extends StatefulWidget {
required this.onTapUp,
required this.onTapDown,
required this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
required this.gestureDetectorBehavior,
Expand All @@ -58,6 +59,7 @@ class PhotoViewCore extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
this.gestureDetectorBehavior,
Expand Down Expand Up @@ -93,6 +95,7 @@ class PhotoViewCore extends StatefulWidget {
final PhotoViewImageTapUpCallback? onTapUp;
final PhotoViewImageTapDownCallback? onTapDown;
final PhotoViewImageScaleEndCallback? onScaleEnd;
final bool? enableDoubleTapZoom;
final bool? enableTapDragZoom;
final PhotoViewDoubleTapZoomEndCallback? onDoubleTapZoomEnd;
final HitTestBehavior? gestureDetectorBehavior;
Expand Down Expand Up @@ -295,7 +298,10 @@ class PhotoViewCoreState extends State<PhotoViewCore>
}

void onDoubleTap() {
nextScaleState();
// default to always enabled even when null
if (widget.enableDoubleTapZoom != false) {
nextScaleState();
}
}

void animateScale(double from, double to) {
Expand Down
9 changes: 3 additions & 6 deletions lib/src/core/photo_view_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class DoubleTapAndTapDragZoomGestureRecognizer
}

void _startDoubleTapTimer() {
_doubleTapTimer ??= Timer(const Duration(milliseconds: 200), _reset);
_doubleTapTimer ??= Timer(kDoubleTapTimeout, _reset);
}

void _stopDoubleTapTimer() {
Expand Down Expand Up @@ -505,10 +505,7 @@ class _TapTracker {
required this.entry,
required Duration doubleTapMinTime,
required this.gestureSettings,
}) : assert(doubleTapMinTime != null),
assert(event != null),
assert(event.buttons != null),
pointer = event.pointer,
}) : pointer = event.pointer,
_initialGlobalPosition = event.position,
_initialLocalPosition = event.localPosition,
initialButtons = event.buttons,
Expand Down Expand Up @@ -554,7 +551,7 @@ class _TapTracker {
}

class _CountdownZoned {
_CountdownZoned({required Duration duration}) : assert(duration != null) {
_CountdownZoned({required Duration duration}) {
Timer(duration, _onTimeout);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/src/photo_view_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ImageWrapper extends StatefulWidget {
required this.onTapUp,
required this.onTapDown,
required this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
required this.outerSize,
Expand Down Expand Up @@ -57,6 +58,7 @@ class ImageWrapper extends StatefulWidget {
final PhotoViewImageTapUpCallback? onTapUp;
final PhotoViewImageTapDownCallback? onTapDown;
final PhotoViewImageScaleEndCallback? onScaleEnd;
final bool? enableDoubleTapZoom;
final bool? enableTapDragZoom;
final PhotoViewDoubleTapZoomEndCallback? onDoubleTapZoomEnd;
final Size outerSize;
Expand Down Expand Up @@ -203,6 +205,7 @@ class _ImageWrapperState extends State<ImageWrapper> {
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
onScaleEnd: widget.onScaleEnd,
enableDoubleTapZoom: widget.enableDoubleTapZoom,
onDoubleTapZoomEnd: widget.onDoubleTapZoomEnd,
enableTapDragZoom: widget.enableTapDragZoom,
gestureDetectorBehavior: widget.gestureDetectorBehavior,
Expand Down Expand Up @@ -254,6 +257,7 @@ class CustomChildWrapper extends StatelessWidget {
this.onTapUp,
this.onTapDown,
this.onScaleEnd,
this.enableDoubleTapZoom,
this.onDoubleTapZoomEnd,
this.enableTapDragZoom,
required this.outerSize,
Expand Down Expand Up @@ -284,6 +288,7 @@ class CustomChildWrapper extends StatelessWidget {
final PhotoViewImageTapUpCallback? onTapUp;
final PhotoViewImageTapDownCallback? onTapDown;
final PhotoViewImageScaleEndCallback? onScaleEnd;
final bool? enableDoubleTapZoom;
final bool? enableTapDragZoom;
final PhotoViewDoubleTapZoomEndCallback? onDoubleTapZoomEnd;
final Size outerSize;
Expand Down Expand Up @@ -318,6 +323,7 @@ class CustomChildWrapper extends StatelessWidget {
onTapUp: onTapUp,
onTapDown: onTapDown,
onScaleEnd: onScaleEnd,
enableDoubleTapZoom: enableDoubleTapZoom,
onDoubleTapZoomEnd: onDoubleTapZoomEnd,
enableTapDragZoom: enableTapDragZoom,
gestureDetectorBehavior: gestureDetectorBehavior,
Expand Down

0 comments on commit 4b71f49

Please sign in to comment.