Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose hit test #209

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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