Support gestureResponseDistance
This commit is contained in:
parent
d56dbd64eb
commit
0bcfcef7ab
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import { Button, View, Text } from 'react-native';
|
||||
import { Dimensions, Button, View, Text } from 'react-native';
|
||||
import { withNavigation } from '@react-navigation/core';
|
||||
import { createStackNavigator } from 'react-navigation-stack';
|
||||
|
||||
|
@ -47,6 +47,9 @@ class ListScreen extends React.Component {
|
|||
class DetailsScreen extends React.Component {
|
||||
static navigationOptions = {
|
||||
title: 'Details',
|
||||
gestureResponseDistance: {
|
||||
horizontal: Dimensions.get('window').width,
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -303,8 +303,24 @@ class StackViewLayout extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
_getGestureResponseDistance = () => {
|
||||
const { scene } = this.props.transitionProps;
|
||||
const { options } = scene.descriptor;
|
||||
const {
|
||||
gestureResponseDistance: userGestureResponseDistance = {},
|
||||
} = options;
|
||||
|
||||
// Doesn't make sense for a response distance of 0, so this works fine
|
||||
return this._isModal()
|
||||
? userGestureResponseDistance.vertical ||
|
||||
GESTURE_RESPONSE_DISTANCE_VERTICAL
|
||||
: userGestureResponseDistance.horizontal ||
|
||||
GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
|
||||
};
|
||||
|
||||
_gestureActivationCriteria = () => {
|
||||
let { layout } = this.props.transitionProps;
|
||||
let gestureResponseDistance = this._getGestureResponseDistance();
|
||||
|
||||
if (this._isMotionVertical()) {
|
||||
let height = layout.height.__getValue();
|
||||
|
@ -312,11 +328,11 @@ class StackViewLayout extends React.Component {
|
|||
return {
|
||||
maxDeltaX: 15,
|
||||
minOffsetY: 5,
|
||||
hitSlop: { bottom: -height + GESTURE_RESPONSE_DISTANCE_VERTICAL },
|
||||
hitSlop: { bottom: -height + gestureResponseDistance },
|
||||
};
|
||||
} else {
|
||||
let width = layout.width.__getValue();
|
||||
let hitSlop = -width + GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
|
||||
let hitSlop = -width + gestureResponseDistance;
|
||||
|
||||
return {
|
||||
minOffsetX: this._isMotionInverted() ? -5 : 5,
|
||||
|
@ -339,6 +355,10 @@ class StackViewLayout extends React.Component {
|
|||
};
|
||||
|
||||
_isMotionVertical = () => {
|
||||
return this._isModal();
|
||||
};
|
||||
|
||||
_isModal = () => {
|
||||
return this.props.mode === 'modal';
|
||||
};
|
||||
|
||||
|
@ -676,8 +696,6 @@ class StackViewLayout extends React.Component {
|
|||
}
|
||||
|
||||
_getTransitionConfig = () => {
|
||||
const isModal = this.props.mode === 'modal';
|
||||
|
||||
return TransitionConfigs.getTransitionConfig(
|
||||
this.props.transitionConfig,
|
||||
{
|
||||
|
@ -685,7 +703,7 @@ class StackViewLayout extends React.Component {
|
|||
position: this._getPosition(),
|
||||
},
|
||||
this.props.lastTransitionProps,
|
||||
isModal
|
||||
this._isModal()
|
||||
);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue