Make GESTURE_RESPONSE_DISTANCE_* configurable. (#2172)

* Make gestureResponseDistance configurable.

* Fix format.

* Set vertical and horizontal distance individually.

* Fix type error.

* Move gestureResponseDistance to NavigationStackScreenOptions.

* Add documentation.
This commit is contained in:
Masayuki Iwai 2017-09-26 04:16:13 +09:00 committed by Lorenzo Sciandra
parent b759d3136e
commit 69397af74d
3 changed files with 15 additions and 2 deletions

View File

@ -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:

View File

@ -282,6 +282,7 @@ export type NavigationStackScreenOptions = {
headerRight?: React.Element<*>,
headerStyle?: ViewStyleProp,
gesturesEnabled?: boolean,
gestureResponseDistance?: { vertical?: number, horizontal?: number },
};
export type NavigationStackRouterConfig = {

View File

@ -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