Created
July 12, 2015 21:23
-
-
Save pcottle/c440e94546a498ce1742 to your computer and use it in GitHub Desktop.
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
componentWillMount() { | |
this._responder = PanOrTapResponder.create({ | |
onPressIn: () => { | |
// Called after the ~30ms delay to make sure | |
// this gesture is not a pan but rather a tap. | |
this.setState({highlightUnderlay: true}); | |
}, | |
onPress: () => { | |
this.setState({highlightUnderlay: false}); | |
this.navigateToFoo(); | |
}, | |
onPressOut: () => { | |
this.setState({highlightUnderlay: false}); | |
// cancelled so do not navigate | |
}, | |
onPanResponderGrant: (e, {dx, dy}) => { | |
invariant( | |
this.state.highlightUnderlay === false, | |
'Cannot be called if press lifecycle is midway through', | |
); | |
this.state.pan.setOffset({x: dx, y: dy}); | |
this.state.pan.setValue({x: 0, y: 0}); | |
}, | |
onPanResponderMove: (e, {dx, dy}) => { | |
this.state.pan.setValue({ | |
x: Math.min(0, dx), | |
}); | |
}, | |
onPanResponderRelease: (e, {dx, dy, vx, vy}) => { | |
// Fancy animation stuff. | |
Animated.decay(this.state.pan.x, { | |
velocity: vx, | |
deceleration: 0.98, | |
}).start(); | |
}, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment