React-native-reanimated: FlatList onScroll event

Created on 4 Dec 2019  路  7Comments  路  Source: software-mansion/react-native-reanimated

Hello All,
I have an issue that when I use FlatList to create horizontal scroll I need to listen for OnScroll event.
When I mapping Native event with event() I receive error that I need to add Animated prefix to FlatList to use event(), however then I receive error:
Invariant violation: element type is invalid: expect a string or class/function but got undefined.

Does FlatList is working in reanimated? When I changed FlatList to ScrollView it worked with Animated.ScrollView .
Do we have any working example with OnScroll and FlatList?

Most helpful comment

I can't make it works, it's like the renderScrollComponent prop is not called.

All 7 comments

Hi @davx1992. react-native-reanimated does not provide an Animated FlatList, but it provides the ScrollView component, so you can use renderScrollComponent to provide an Animated ScrollView to your FlatList:

<FlatList 
  {...props}
  renderScrollComponent={(props) => <ScrollView {...props} onScroll={(evt) => {
    console.log(evt);
  }} />}
/>

Thank you @terrysahaidak, will try with your example.

I can't make it works, it's like the renderScrollComponent prop is not called.

It doesn't work with me too

Hi @MoeMamdouh, could you provide a snack or some sample code, please?

I have an Animated.createAnimatedComponent(FlatList) and it doesn't seem to be firing the onScroll={({ nativeEvent }) => console.log(nativeEvent)}

Adding a Animated.ScrollView to renderScrollComponent allows it to fire now but the reason I wanted a flatlist is for it's performance properties in the first place so making the scroll component a scroll view kinda defeats the purpose.

@CoryWritesCode, please provide a small repro we can test it on.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

levibuzolic picture levibuzolic  路  3Comments

bdrobinson picture bdrobinson  路  3Comments

colinux picture colinux  路  3Comments

zxccvvv picture zxccvvv  路  3Comments

ShaMan123 picture ShaMan123  路  3Comments