Skip to content

Commit

Permalink
Merge pull request #14 from zim32/zim32-patch-1
Browse files Browse the repository at this point in the history
Add backGestureDetectionStart parameter
  • Loading branch information
JonasWanke committed Jun 9, 2021
2 parents b4c8eaa + 5324ad5 commit ae6f072
Showing 1 changed file with 11 additions and 4 deletions.
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 @@ -51,12 +52,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;

/// 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;

@override
bool get popGestureEnabled => canSwipe && super.popGestureEnabled;
Expand Down Expand Up @@ -103,6 +106,7 @@ class SwipeablePageRoute<T> extends CupertinoPageRoute<T> {
onStartPopGesture: _startPopGesture,
canOnlySwipeFromEdge: canOnlySwipeFromEdge,
backGestureDetectionWidth: backGestureDetectionWidth,
backGestureDetectionStart: backGestureDetectionStart,
child: child,
),
);
Expand Down Expand Up @@ -136,13 +140,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 @@ -225,6 +231,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 @@ -237,7 +244,7 @@ class _FancyBackGestureDetectorState<T>
widget.child,
if (widget.canOnlySwipeFromEdge)
PositionedDirectional(
start: 0,
start: widget.backGestureDetectionStart,
width: dragAreaWidth,
top: 0,
bottom: 0,
Expand Down

0 comments on commit ae6f072

Please sign in to comment.