Skip to content

Instantly share code, notes, and snippets.

@pcottle
Created July 12, 2015 21:22
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/44f6c0b626fd086d97c6 to your computer and use it in GitHub Desktop.
Save pcottle/44f6c0b626fd086d97c6 to your computer and use it in GitHub Desktop.
componentWillMount() {
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onPanResponderGrant: (e, {dx, dy}) => {
this.state.pan.setOffset({x: dx, y: dy});
this.state.pan.setValue({x: 0, y: 0});
setTimeout(() => {
// tapping and not moving, so show the progress
if (this.state.pan.x.__getValue() === 0) {
this.setState({
highlighted: true,
});
}
}, 30);
},
onPanResponderMove: (e, {dx, dy}) => {
this.setState({
highlighted: false,
});
this.state.pan.setValue({
x: Math.min(0, dx),
});
},
onPanResponderRelease: (e, {dx, dy, vx, vy}) => {
this.setState({
highlighted: false,
});
if (dx === 0 && dy === 0) {
// tap action, so go do that
var trip = this.props.trip;
TripActions.setFavoritesGuard(true);
TripActions.selectDeparture(trip.departureID);
TripActions.selectArrival(trip.arrivalID);
TripActions.setFavoritesGuard(false);
this.props.navigator.push(
Routes.getRouteForID(Routes.TIMES)
);
return;
}
if (Math.abs(dx) > DecisionThreshold) {
Animated.decay(this.state.pan.x, {
velocity: vx,
deceleration: 0.98,
}).start(() => {
var trip = this.props.trip;
TripActions.removeFavoriteTrip(
trip.departureID,
trip.arrivalID
);
LayoutAnimation.easeInEaseOut();
this._resetState();
});
} else {
Animated.spring(this.state.pan, {
toValue: {x: 0, y: 0},
friction: 3,
}).start();
}
},
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment