Created
November 13, 2019 08:17
-
-
Save rcerrejon/f354f8330e51448c2258beb95a0ee9f6 to your computer and use it in GitHub Desktop.
swipe React Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { View, Animated, PanResponder } from 'react-native' | |
// onSwipePerformed = action => { | |
// switch (action) { | |
// case 'left': { | |
// // this.switchTo(1) | |
// console.log('left Swipe performed') | |
// break | |
// } | |
// case 'right': { | |
// // this.switchTo(0) | |
// console.log('right Swipe performed') | |
// break | |
// } | |
// default: { | |
// console.log('Kein Bewegung') | |
// } | |
// } | |
// } | |
export default class SwipeGesture extends Component { | |
componentWillMount = () => { | |
this.PanResponder = PanResponder.create({ | |
onStartShouldSetPanResponder: (evt, gestureState) => true, | |
onPanResponderRelease: (evt, gestureState) => { | |
let x = gestureState.dx | |
let y = gestureState.dy | |
if (Math.abs(x) > Math.abs(y)) { | |
if (x >= 0) { | |
this.props.onSwipePerformed('right') | |
} else { | |
this.props.onSwipePerformed('left') | |
} | |
} | |
} | |
}) | |
} | |
render() { | |
return ( | |
<Animated.View | |
{...this.PanResponder.panHandlers} | |
style={this.props.gestureStyle} | |
> | |
<View>{this.props.children}</View> | |
</Animated.View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment