Support for preventing swipe left or swipe right
Summary: The primary use case for this is disabling swipe right when using react-navigation's swipe to go back feature. Closes https://github.com/facebook/react-native/pull/14684 Differential Revision: D5386554 Pulled By: sahrens fbshipit-source-id: 1e7c4caaa804f86977d391c1bdb62be69342b551
This commit is contained in:
parent
dedffdc235
commit
bf1b67ee5f
|
@ -72,6 +72,8 @@ const SwipeableRow = createReactClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
isOpen: PropTypes.bool,
|
isOpen: PropTypes.bool,
|
||||||
|
preventSwipeLeft: PropTypes.bool,
|
||||||
|
preventSwipeRight: PropTypes.bool,
|
||||||
maxSwipeDistance: PropTypes.number.isRequired,
|
maxSwipeDistance: PropTypes.number.isRequired,
|
||||||
onOpen: PropTypes.func.isRequired,
|
onOpen: PropTypes.func.isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
|
@ -108,6 +110,8 @@ const SwipeableRow = createReactClass({
|
||||||
getDefaultProps(): Object {
|
getDefaultProps(): Object {
|
||||||
return {
|
return {
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
preventSwipeLeft: false,
|
||||||
|
preventSwipeRight: false,
|
||||||
maxSwipeDistance: 0,
|
maxSwipeDistance: 0,
|
||||||
onOpen: emptyFunction,
|
onOpen: emptyFunction,
|
||||||
onClose: emptyFunction,
|
onClose: emptyFunction,
|
||||||
|
@ -335,6 +339,12 @@ const SwipeableRow = createReactClass({
|
||||||
|
|
||||||
// Ignore swipes due to user's finger moving slightly when tapping
|
// Ignore swipes due to user's finger moving slightly when tapping
|
||||||
_isValidSwipe(gestureState: Object): boolean {
|
_isValidSwipe(gestureState: Object): boolean {
|
||||||
|
if (this.props.preventSwipeLeft && gestureState.dx < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.props.preventSwipeRight && gestureState.dx > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return Math.abs(gestureState.dx) > HORIZONTAL_SWIPE_DISTANCE_THRESHOLD;
|
return Math.abs(gestureState.dx) > HORIZONTAL_SWIPE_DISTANCE_THRESHOLD;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue