Skip to content

Instantly share code, notes, and snippets.

@pcottle
Created July 12, 2015 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcottle/c440e94546a498ce1742 to your computer and use it in GitHub Desktop.
Save pcottle/c440e94546a498ce1742 to your computer and use it in GitHub Desktop.
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