Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/Release/lib
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
.history
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Can be passed within optional `config` property.
| velocityThreshold | Number | 0.3 | Velocity that has to be breached in order for swipe to be triggered (`vx` and `vy` properties of `gestureState`) |
| directionalOffsetThreshold | Number | 80 | Absolute offset that shouldn't be breached for swipe to be triggered (`dy` for horizontal swipe, `dx` for vertical swipe) |
| gestureIsClickThreshold | Number | 5 | Absolute distance that should be breached for the gesture to not be considered a click (`dx` or `dy` properties of `gestureState`) |
|needVerticalScroll|Boolean|false|Need vertical scroll or not|
|scrollVerticalThreshold|Number|5|Absolute distance that to decide if give touch event to ScrollView|

## Methods

Expand Down
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ declare module 'react-native-swipe-gestures' {
* @default 5
*/
gestureIsClickThreshold?: number;

/**
* Need vertical scroll or not
* @default false
*/
needVerticalScroll?: Boolean;

/**
* Absolute distance that to decide if give touch event to ScrollView
* @default 5
*/
scrollVerticalThreshold?: number;
}

class GestureRecognizer extends Component<GestureRecognizerProps> {}
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const swipeDirections = {
const swipeConfig = {
velocityThreshold: 0.3,
directionalOffsetThreshold: 80,
gestureIsClickThreshold: 5
gestureIsClickThreshold: 5,
needVerticalScroll: false,
scrollVerticalThreshold: 5
};

function isValidSwipe(
Expand Down Expand Up @@ -50,6 +52,16 @@ class GestureRecognizer extends Component {
}

_handleShouldSetPanResponder(evt, gestureState) {

// start --- 2020/12/4 fix the problem that scroll view can't work inside on ios
if (this.swipeConfig.needVerticalScroll
&& ( gestureState.dy > this.swipeConfig.scrollVerticalThreshold
|| gestureState.dy < -this.swipeConfig.scrollVerticalThreshold )
) {
return false
}
// end --- 2020/12/4 fix the problem that scroll view can't work inside on ios

return (
evt.nativeEvent.touches.length === 1 &&
!this._gestureIsClick(gestureState)
Expand Down