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