I have a FlatList with an onScroll function that looks like this:
<Animated.View style={{ transform: [{translateX: this.state.scrollX}] }}>
<FlatList
data={ reactionGroup.reactions }
keyExtractor={ (i) => i.id + uuid.v4() }
renderItem={ this._renderItem }
horizontal={ true }
scrollEventThrottle={1}
onScroll={ reactionGroup.reactions.length > 1 ? this.onScroll : null }
showsHorizontalScrollIndicator={ false } />
</Animated.View>
onScroll(event) {
const { timing } = Animated
if (event.nativeEvent.contentOffset.x > 0) {
timing(
this.state.scrollX,
{ toValue: -60, duration: 100, useNativeDriver: true }
).start()
} else {
timing(
this.state.scrollX,
{ toValue: 0, duration: 100, useNativeDriver: true }
).start()
}
},
This works fine on iOS, but for Android, the animation won't start until FlatList stops scrolling.
Basically, I just start the animation when the user scrolls and sets it back when they return to the beginning of the horizontal scroll.
Is there a better way to handle this, so it works on Android?
I also tried doing Animation.event inside onScroll, but I don't want to snap the animation directly to the scroll position. This approach allowed Android to animate while scrolling, but it was pretty nervous.
RN: 0.43.3
source
share