From 583e19eac40904b39e74e5a5dc27ae839c14d1af Mon Sep 17 00:00:00 2001 From: renancaraujo Date: Tue, 19 Nov 2019 22:15:53 +0000 Subject: [PATCH] expose hit test --- lib/photo_view.dart | 7 +++++ lib/photo_view_gallery.dart | 7 +++++ lib/src/core/photo_view_core.dart | 31 ++++++++++--------- lib/src/core/photo_view_gesture_detector.dart | 5 ++- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/photo_view.dart b/lib/photo_view.dart index c9f85767..e226c025 100644 --- a/lib/photo_view.dart +++ b/lib/photo_view.dart @@ -240,6 +240,7 @@ class PhotoView extends StatefulWidget { this.onTapUp, this.onTapDown, this.customSize, + this.gestureDetectorBehavior, }) : child = null, childSize = null, super(key: key); @@ -268,6 +269,7 @@ class PhotoView extends StatefulWidget { this.onTapUp, this.onTapDown, this.customSize, + this.gestureDetectorBehavior, }) : loadingChild = null, imageProvider = null, gaplessPlayback = false, @@ -344,6 +346,9 @@ class PhotoView extends StatefulWidget { /// location. final PhotoViewImageTapDownCallback onTapDown; + /// [HitTestBehavior] to be passed to the internal gesture detector. + final HitTestBehavior gestureDetectorBehavior; + @override State createState() { return _PhotoViewState(); @@ -501,6 +506,7 @@ class _PhotoViewState extends State { scaleBoundaries: scaleBoundaries, onTapUp: widget.onTapUp, onTapDown: widget.onTapDown, + gestureDetectorBehavior: widget.gestureDetectorBehavior, ); } @@ -553,6 +559,7 @@ class _PhotoViewState extends State { scaleBoundaries: scaleBoundaries, onTapUp: widget.onTapUp, onTapDown: widget.onTapDown, + gestureDetectorBehavior: widget.gestureDetectorBehavior, ); } diff --git a/lib/photo_view_gallery.dart b/lib/photo_view_gallery.dart index f3038587..351addfc 100644 --- a/lib/photo_view_gallery.dart +++ b/lib/photo_view_gallery.dart @@ -234,6 +234,7 @@ class _PhotoViewGalleryState extends State { scaleStateCycle: pageOption.scaleStateCycle, onTapUp: pageOption.onTapUp, onTapDown: pageOption.onTapDown, + gestureDetectorBehavior: pageOption.gestureDetectorBehavior, ) : PhotoView( key: ObjectKey(index), @@ -253,6 +254,7 @@ class _PhotoViewGalleryState extends State { scaleStateCycle: pageOption.scaleStateCycle, onTapUp: pageOption.onTapUp, onTapDown: pageOption.onTapDown, + gestureDetectorBehavior: pageOption.gestureDetectorBehavior, ); return ClipRect( @@ -287,6 +289,7 @@ class PhotoViewGalleryPageOptions { this.scaleStateCycle, this.onTapUp, this.onTapDown, + this.gestureDetectorBehavior, }) : child = null, childSize = null, assert(imageProvider != null); @@ -304,6 +307,7 @@ class PhotoViewGalleryPageOptions { this.scaleStateCycle, this.onTapUp, this.onTapDown, + this.gestureDetectorBehavior, }) : imageProvider = null, assert(child != null), assert(childSize != null); @@ -346,4 +350,7 @@ class PhotoViewGalleryPageOptions { /// Mirror to [PhotoView.onTapDown] final PhotoViewImageTapDownCallback onTapDown; + + /// Mirror to [PhotoView.gestureDetectorBehavior] + final HitTestBehavior gestureDetectorBehavior; } diff --git a/lib/src/core/photo_view_core.dart b/lib/src/core/photo_view_core.dart index b0282952..822c4f31 100644 --- a/lib/src/core/photo_view_core.dart +++ b/lib/src/core/photo_view_core.dart @@ -19,13 +19,13 @@ class PhotoViewCore extends StatefulWidget { const PhotoViewCore({ Key key, @required this.imageProvider, - this.backgroundDecoration, - this.gaplessPlayback = false, - this.heroAttributes, - this.enableRotation, - this.onTapUp, - this.onTapDown, - this.index, + @required this.backgroundDecoration, + @required this.gaplessPlayback, + @required this.heroAttributes, + @required this.enableRotation, + @required this.onTapUp, + @required this.onTapDown, + @required this.gestureDetectorBehavior, @required this.controller, @required this.scaleBoundaries, @required this.scaleStateCycle, @@ -37,12 +37,12 @@ class PhotoViewCore extends StatefulWidget { const PhotoViewCore.customChild({ Key key, @required this.customChild, - this.backgroundDecoration, - this.heroAttributes, - this.enableRotation, - this.onTapUp, - this.onTapDown, - this.index, + @required this.backgroundDecoration, + @required this.heroAttributes, + @required this.enableRotation, + @required this.onTapUp, + @required this.onTapDown, + @required this.gestureDetectorBehavior, @required this.controller, @required this.scaleBoundaries, @required this.scaleStateCycle, @@ -52,7 +52,6 @@ class PhotoViewCore extends StatefulWidget { gaplessPlayback = false, super(key: key); - final int index; final Decoration backgroundDecoration; final ImageProvider imageProvider; final bool gaplessPlayback; @@ -69,6 +68,8 @@ class PhotoViewCore extends StatefulWidget { final PhotoViewImageTapUpCallback onTapUp; final PhotoViewImageTapDownCallback onTapDown; + final HitTestBehavior gestureDetectorBehavior; + @override State createState() { return PhotoViewCoreState(); @@ -334,7 +335,7 @@ class PhotoViewCoreState extends State ? widget.customChild : Image( image: widget.imageProvider, - gaplessPlayback: widget.gaplessPlayback, + gaplessPlayback: widget.gaplessPlayback ?? false, ); } } diff --git a/lib/src/core/photo_view_gesture_detector.dart b/lib/src/core/photo_view_gesture_detector.dart index 3accbbad..323828a1 100644 --- a/lib/src/core/photo_view_gesture_detector.dart +++ b/lib/src/core/photo_view_gesture_detector.dart @@ -14,6 +14,7 @@ class PhotoViewGestureDetector extends StatelessWidget { this.child, this.onTapUp, this.onTapDown, + this.behavior, }) : super(key: key); final GestureDoubleTapCallback onDoubleTap; @@ -28,6 +29,8 @@ class PhotoViewGestureDetector extends StatelessWidget { final Widget child; + final HitTestBehavior behavior; + @override Widget build(BuildContext context) { final scope = PhotoViewGestureDetectorScope.of(context); @@ -69,7 +72,7 @@ class PhotoViewGestureDetector extends StatelessWidget { ); return RawGestureDetector( - behavior: HitTestBehavior.translucent, + behavior: behavior ?? HitTestBehavior.translucent, child: child, gestures: gestures, );