Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PanResponder example
constructor(props: Props) {
super(props);
this.pan.addListener((value) => this.position = value);
this.panResponder = PanResponder.create({
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onPanResponderGrant: () => {
this.pan.setOffset({
x: this.position.x,
y: this.position.y
});
this.pan.setValue({ x: 0, y: 0 });
},
// Move object while onPress is active. Snapping is handled later.
onPanResponderMove: Animated.event([
null, { dx: this.pan.x, dy: this.pan.y }
]),
// Handle swiper behaviour after object is released.
onPanResponderRelease: (e, { dx, dy, vx }) => {
// Fix jumping when moving the object second time.
this.pan.flattenOffset();
// Send ending position to parent component.
this.props.calculateOverlapping(dx, dy, this.props.person.id);
// Animate springy tuff.
Animated.spring(this.pan, { toValue: { x: 0, y: 0 } }).start();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.