From d08dd64e9377a256919acf7a59ad0b5d7eed10b1 Mon Sep 17 00:00:00 2001 From: Luke Rhodes Date: Thu, 22 Jun 2017 23:36:43 +1000 Subject: [PATCH] Support for preventing swipe left or swipe right The primary use case for this is disabling swipe right when using react-navigation's swipe to go back feature. --- Libraries/Experimental/SwipeableRow/SwipeableRow.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Libraries/Experimental/SwipeableRow/SwipeableRow.js b/Libraries/Experimental/SwipeableRow/SwipeableRow.js index 5a7c575c4f2094..78ce25d4df692e 100644 --- a/Libraries/Experimental/SwipeableRow/SwipeableRow.js +++ b/Libraries/Experimental/SwipeableRow/SwipeableRow.js @@ -70,6 +70,8 @@ const SwipeableRow = React.createClass({ propTypes: { children: PropTypes.any, isOpen: PropTypes.bool, + preventSwipeLeft: PropTypes.bool, + preventSwipeRight: PropTypes.bool, maxSwipeDistance: PropTypes.number.isRequired, onOpen: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, @@ -106,6 +108,8 @@ const SwipeableRow = React.createClass({ getDefaultProps(): Object { return { isOpen: false, + preventSwipeLeft: false, + preventSwipeRight: false, maxSwipeDistance: 0, onOpen: emptyFunction, onClose: emptyFunction, @@ -327,6 +331,12 @@ const SwipeableRow = React.createClass({ // Ignore swipes due to user's finger moving slightly when tapping _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; },