Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect swipe left in React Native

Tags:

How can I detect a left swipe on the entire screen in React Native?

Would it be necessary to use PanResponder or can it be done a little more easy?

like image 518
Jamgreen Avatar asked Aug 24 '17 06:08

Jamgreen


2 Answers

There is an existing component react-native-swipe-gestures for handling swipe gestures in up, down, left and right direction, see https://github.com/glepur/react-native-swipe-gestures

like image 167
Bhavan Patel Avatar answered Oct 13 '22 17:10

Bhavan Patel


I've found that react-native-swipe-gestures isn't stable (swipes works randomly on android) and react-native-gesture-handler is overcomplicated (too much efforts to just add to project).

Simplified solution based on Kuza Grave's answer, who's solution works perfect and very simple:

<View       onTouchStart={e=> this.touchY = e.nativeEvent.pageY}       onTouchEnd={e => {         if (this.touchY - e.nativeEvent.pageY > 20)           console.log('Swiped up')       }}       style={{height: 300, backgroundColor: '#ccc'}}     /> 
like image 21
Daniel Garmoshka Avatar answered Oct 13 '22 16:10

Daniel Garmoshka