Skip to content

Commit

Permalink
Support for preventing swipe left or swipe right
Browse files Browse the repository at this point in the history
Summary:
The primary use case for this is disabling swipe right when using react-navigation's swipe to go back feature.
Closes #14684

Differential Revision: D5386554

Pulled By: sahrens

fbshipit-source-id: 1e7c4caaa804f86977d391c1bdb62be69342b551
  • Loading branch information
lprhodes authored and facebook-github-bot committed Jul 8, 2017
1 parent dedffdc commit bf1b67e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Libraries/Experimental/SwipeableRow/SwipeableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const SwipeableRow = createReactClass({
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,
Expand Down Expand Up @@ -108,6 +110,8 @@ const SwipeableRow = createReactClass({
getDefaultProps(): Object {
return {
isOpen: false,
preventSwipeLeft: false,
preventSwipeRight: false,
maxSwipeDistance: 0,
onOpen: emptyFunction,
onClose: emptyFunction,
Expand Down Expand Up @@ -335,6 +339,12 @@ const SwipeableRow = createReactClass({

// 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;
},

Expand Down

0 comments on commit bf1b67e

Please sign in to comment.