Skip to content

Commit

Permalink
increase the threshold to register a swipe on the toast container (#144)
Browse files Browse the repository at this point in the history
* increase the threshold to register a swipe on the toast container

* extract logic as to whether pan responder should respond to a gesture
  • Loading branch information
kennethsoftware committed Feb 10, 2021
1 parent 5edc1e6 commit 8e06759
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Toast extends Component {
this._setState = this._setState.bind(this);
this._animateMovement = this._animateMovement.bind(this);
this._animateRelease = this._animateRelease.bind(this);
this._shouldSetPanResponder = this._shouldSetPanResponder.bind(this);
this.startTimer = this.startTimer.bind(this);
this.animate = this.animate.bind(this);
this.show = this.show.bind(this);
Expand All @@ -102,11 +103,10 @@ class Toast extends Component {
};

this.panResponder = PanResponder.create({
onMoveShouldSetPanResponder: (event, gestureState) => {
const { dx, dy } = gestureState;
// Fixes onPress handler https://github.com/calintamas/react-native-toast-message/issues/113
return Math.abs(dx) > 1 || Math.abs(dy) > 1;
},
onMoveShouldSetPanResponder: (event, gesture) =>
this._shouldSetPanResponder(gesture),
onMoveShouldSetPanResponderCapture: (event, gesture) =>
this._shouldSetPanResponder(gesture),
onPanResponderMove: (event, gesture) => {
this._animateMovement(gesture);
},
Expand Down Expand Up @@ -158,6 +158,12 @@ class Toast extends Component {
return new Promise((resolve) => this.setState(reducer, () => resolve()));
}

_shouldSetPanResponder(gesture) {
const { dx, dy } = gesture;
// Fixes onPress handler https://github.com/calintamas/react-native-toast-message/issues/113
return Math.abs(dx) > 2 || Math.abs(dy) > 2;
}

_animateMovement(gesture) {
const { position, animation, keyboardVisible } = this.state;
const { dy } = gesture;
Expand Down

0 comments on commit 8e06759

Please sign in to comment.