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

Add backGestureDetectionStart parameter #14

Merged
merged 1 commit into from Jun 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/src/page_route.dart
Expand Up @@ -15,6 +15,7 @@ class SwipeablePageRoute<T> extends CupertinoPageRoute<T> {
this.canSwipe = true,
this.canOnlySwipeFromEdge = false,
this.backGestureDetectionWidth = kMinInteractiveDimension,
this.backGestureDetectionStart = 0.0,
required WidgetBuilder builder,
String? title,
RouteSettings? settings,
Expand Down Expand Up @@ -43,12 +44,14 @@ class SwipeablePageRoute<T> extends CupertinoPageRoute<T> {
/// If set to `false`, the user can start dragging anywhere on the screen.
final bool canOnlySwipeFromEdge;

/// If [canOnlySwipeFromEdge] is set to `true`, this value controls
/// width of gesture detection area
final double backGestureDetectionWidth;
Comment on lines +47 to +49
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If [canOnlySwipeFromEdge] is set to `true`, this value controls
/// width of gesture detection area
final double backGestureDetectionWidth;
/// If [canOnlySwipeFromEdge] is set to `true`, this value controls the width
/// of the gesture detection area.
///
/// For comparison, in [CupertinoPageRoute] this value is `20`.


/// If [canOnlySwipeFromEdge] is set to `true`, this value controls how far
/// away from the left (LTR) or right (RTL) screen edge a gesture must start
/// to be recognized for back navigation.
///
/// In [CupertinoPageRoute], this value is `20`.
final double backGestureDetectionWidth;
final double backGestureDetectionStart;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming this to backGestureDetectionStartOffset? That might be more explicit and easier to understand without having to read the doc comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backGestureDetectionStart looks fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I mean backGestureDetectionStartOffset
You should fix change


@override
bool get popGestureEnabled => canSwipe && super.popGestureEnabled;
Expand Down Expand Up @@ -95,6 +98,7 @@ class SwipeablePageRoute<T> extends CupertinoPageRoute<T> {
onStartPopGesture: _startPopGesture,
canOnlySwipeFromEdge: canOnlySwipeFromEdge,
backGestureDetectionWidth: backGestureDetectionWidth,
backGestureDetectionStart: backGestureDetectionStart,
child: child,
),
);
Expand Down Expand Up @@ -128,13 +132,15 @@ class _FancyBackGestureDetector<T> extends StatefulWidget {
Key? key,
required this.canOnlySwipeFromEdge,
required this.backGestureDetectionWidth,
required this.backGestureDetectionStart,
required this.enabledCallback,
required this.onStartPopGesture,
required this.child,
}) : super(key: key);

final bool canOnlySwipeFromEdge;
final double backGestureDetectionWidth;
final double backGestureDetectionStart;

final Widget child;
final ValueGetter<bool> enabledCallback;
Expand Down Expand Up @@ -217,6 +223,7 @@ class _FancyBackGestureDetectorState<T>
: MediaQuery.of(context).padding.right;
dragAreaWidth = max(dragAreaWidth, widget.backGestureDetectionWidth);


final listener = Listener(
onPointerDown: (event) {
if (widget.enabledCallback()) _recognizer.addPointer(event);
Expand All @@ -229,7 +236,7 @@ class _FancyBackGestureDetectorState<T>
widget.child,
if (widget.canOnlySwipeFromEdge)
PositionedDirectional(
start: 0,
start: widget.backGestureDetectionStart,
width: dragAreaWidth,
top: 0,
bottom: 0,
Expand Down