Created
September 23, 2019 08:21
-
-
Save sebastijandumancic/4ff2184aac4dd88770f6bb66f5be998f to your computer and use it in GitHub Desktop.
PanResponder example
This file contains 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
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
Hi, I stucking in click in any bubble then expand a ChatView + move/show all bubble to top of screen like Messenger. Do you have any solution?