I am currently using ScrollView to hold all my cards like
<ScrollView>
<Card id={1}/>
<Card id={2}/>
</ScrollView>
Card
is a customised component which is basically just a View with certain width and height.
I used PanResponder to define the drag animation and attach the handlers to each of the Card.
this._panResponder = PanResponder.create({
onPanResponderGrant: (e, gestureState) => {
this.state.pan.setOffset({x: this.state.pan.x._value, y: this.state.pan.y._value});
},
onPanResponderMove: Animated.event([
null, {dx: this.state.pan.x, dy: this.state.pan.y},
]),
onPanResponderRelease: (e, {vx, vy}) => {
this.state.pan.flattenOffset()
}
});
So Card
component just render the animated view like
<Animated.View {...this._panResponder.panHandlers}>
...
</Animated.View>
I can drag the card anywhere inside the scroll view, the part overflow the scroll view will be hided. how I can make the Card on top of the scrollView, then I can drag and show it anywhere across the screen.
The interesting thing that I found when I change ScrollView
to View
, then the Card
can be dragged on top of the View
. It only work on iOS, Android still be the same as ScrollView
.