Skip to content

Commit

Permalink
Make GESTURE_RESPONSE_DISTANCE_* configurable. (#2172)
Browse files Browse the repository at this point in the history
* Make gestureResponseDistance configurable.

* Fix format.

* Set vertical and horizontal distance individually.

* Fix type error.

* Move gestureResponseDistance to NavigationStackScreenOptions.

* Add documentation.
  • Loading branch information
miyabi authored and kelset committed Sep 25, 2017
1 parent b759d31 commit 69397af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/api/navigators/StackNavigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ Color for material ripple (Android >= 5.0 only)

Whether you can use gestures to dismiss this screen. Defaults to true on iOS, false on Android.

#### `gestureResponseDistance`

Object to override the distance of touch start from the edge of the screen to recognize gestures. It takes the following properties:

- `horizontal` - *number* - Distance for horizontal direction. Defaults to 25.
- `vertical` - *number* - Distance for vertical direction. Defaults to 135.

### Navigator Props

The navigator component created by `StackNavigator(...)` takes the following props:
Expand Down
1 change: 1 addition & 0 deletions src/TypeDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export type NavigationStackScreenOptions = {
headerRight?: React.Element<*>,
headerStyle?: ViewStyleProp,
gesturesEnabled?: boolean,
gestureResponseDistance?: { vertical?: number, horizontal?: number },
};

export type NavigationStackRouterConfig = {
Expand Down
9 changes: 7 additions & 2 deletions src/views/CardStack/CardStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,14 @@ class CardStack extends Component {
// Measure the distance from the touch to the edge of the screen
const screenEdgeDistance = currentDragPosition - currentDragDistance;
// Compare to the gesture distance relavant to card or modal
const {
gestureResponseDistance: userGestureResponseDistance = {},
} = this._getScreenDetails(scene).options;
const gestureResponseDistance = isVertical
? GESTURE_RESPONSE_DISTANCE_VERTICAL
: GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
? userGestureResponseDistance.vertical ||
GESTURE_RESPONSE_DISTANCE_VERTICAL
: userGestureResponseDistance.horizontal ||
GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
// GESTURE_RESPONSE_DISTANCE is about 25 or 30. Or 135 for modals
if (screenEdgeDistance > gestureResponseDistance) {
// Reject touches that started in the middle of the screen
Expand Down

0 comments on commit 69397af

Please sign in to comment.