Skip to content

Commit

Permalink
expose hit test (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
renancaraujo authored Nov 19, 2019
1 parent c990569 commit a4fb817
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
7 changes: 7 additions & 0 deletions lib/photo_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class PhotoView extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.customSize,
this.gestureDetectorBehavior,
}) : child = null,
childSize = null,
super(key: key);
Expand Down Expand Up @@ -268,6 +269,7 @@ class PhotoView extends StatefulWidget {
this.onTapUp,
this.onTapDown,
this.customSize,
this.gestureDetectorBehavior,
}) : loadingChild = null,
imageProvider = null,
gaplessPlayback = false,
Expand Down Expand Up @@ -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<StatefulWidget> createState() {
return _PhotoViewState();
Expand Down Expand Up @@ -501,6 +506,7 @@ class _PhotoViewState extends State<PhotoView> {
scaleBoundaries: scaleBoundaries,
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
gestureDetectorBehavior: widget.gestureDetectorBehavior,
);
}

Expand Down Expand Up @@ -553,6 +559,7 @@ class _PhotoViewState extends State<PhotoView> {
scaleBoundaries: scaleBoundaries,
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
gestureDetectorBehavior: widget.gestureDetectorBehavior,
);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
scaleStateCycle: pageOption.scaleStateCycle,
onTapUp: pageOption.onTapUp,
onTapDown: pageOption.onTapDown,
gestureDetectorBehavior: pageOption.gestureDetectorBehavior,
)
: PhotoView(
key: ObjectKey(index),
Expand All @@ -253,6 +254,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
scaleStateCycle: pageOption.scaleStateCycle,
onTapUp: pageOption.onTapUp,
onTapDown: pageOption.onTapDown,
gestureDetectorBehavior: pageOption.gestureDetectorBehavior,
);

return ClipRect(
Expand Down Expand Up @@ -287,6 +289,7 @@ class PhotoViewGalleryPageOptions {
this.scaleStateCycle,
this.onTapUp,
this.onTapDown,
this.gestureDetectorBehavior,
}) : child = null,
childSize = null,
assert(imageProvider != null);
Expand All @@ -304,6 +307,7 @@ class PhotoViewGalleryPageOptions {
this.scaleStateCycle,
this.onTapUp,
this.onTapDown,
this.gestureDetectorBehavior,
}) : imageProvider = null,
assert(child != null),
assert(childSize != null);
Expand Down Expand Up @@ -346,4 +350,7 @@ class PhotoViewGalleryPageOptions {

/// Mirror to [PhotoView.onTapDown]
final PhotoViewImageTapDownCallback onTapDown;

/// Mirror to [PhotoView.gestureDetectorBehavior]
final HitTestBehavior gestureDetectorBehavior;
}
31 changes: 16 additions & 15 deletions lib/src/core/photo_view_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -69,6 +68,8 @@ class PhotoViewCore extends StatefulWidget {
final PhotoViewImageTapUpCallback onTapUp;
final PhotoViewImageTapDownCallback onTapDown;

final HitTestBehavior gestureDetectorBehavior;

@override
State<StatefulWidget> createState() {
return PhotoViewCoreState();
Expand Down Expand Up @@ -334,7 +335,7 @@ class PhotoViewCoreState extends State<PhotoViewCore>
? widget.customChild
: Image(
image: widget.imageProvider,
gaplessPlayback: widget.gaplessPlayback,
gaplessPlayback: widget.gaplessPlayback ?? false,
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/photo_view_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PhotoViewGestureDetector extends StatelessWidget {
this.child,
this.onTapUp,
this.onTapDown,
this.behavior,
}) : super(key: key);

final GestureDoubleTapCallback onDoubleTap;
Expand All @@ -28,6 +29,8 @@ class PhotoViewGestureDetector extends StatelessWidget {

final Widget child;

final HitTestBehavior behavior;

@override
Widget build(BuildContext context) {
final scope = PhotoViewGestureDetectorScope.of(context);
Expand Down Expand Up @@ -69,7 +72,7 @@ class PhotoViewGestureDetector extends StatelessWidget {
);

return RawGestureDetector(
behavior: HitTestBehavior.translucent,
behavior: behavior ?? HitTestBehavior.translucent,
child: child,
gestures: gestures,
);
Expand Down

0 comments on commit a4fb817

Please sign in to comment.