Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase the threshold to register a swipe on the toast container #144

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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