Search code examples
javascripttypescriptreact-nativereact-native-flatlistreact-native-reanimated

React Native Flatlist Auto Scrolling


i have an flatlist component which i would like to make it auto scrolling.

<FlatList
        contentContainerStyle={{}}
        data={banners}
        renderItem={(item) => (
          <Image source={{ uri: item.item }} style={styles.image} />
        )}
        horizontal
        showsHorizontalScrollIndicator={false}
        snapToInterval={width}
        snapToAlignment={'center'}
        decelerationRate={'fast'}
      />

Here is the component so far what property i need for it instead of setInterval any other idea?

I have searched some old solutions from past year which are outdated already. I would like to have something with less lines of code and easier to apply.


Solution

  • If you want minimal lines of code and don't want to handle triggering the scroll yourself, you should use a carousel package like this one:

    https://github.com/dohooo/react-native-reanimated-carousel#readme