how can we autoscroll and autoloop flatlist in react native

2.4k Views Asked by At

I want my Flatlist autoscroll and loop in horizontal direction, please help me out Thanks in Advance

          <FlatList
             style={{marginEnd:5}}
             timer={2000}
             //  width={deviceWidth}
              loop={true}
             // keyExtractor={this._keyExtractor.bind(this)}
              horizontal={true}
              onScrollToIndexFailed={info => {
                 const wait = new Promise(resolve => setTimeout(resolve, 500));
                 wait.then(() => {
                    flatListFeaturedMobiles.current?.scrollToIndex({ index: info.index, animated: true });
                 });
               }}
             //  onScrollToIndexFailed={()=>{}}
              flatListRef={React.createRef()}
              ref={this.flatListFeaturedMobiles}
              autoscroll={true}
              
            showsHorizontalScrollIndicator={false}
        data={this.state.featuredMobiles}
        horizontal
1

There are 1 best solutions below

2
On

You can scroll the list using Animated like check it How do I make a list (FlatList) automatically scroll

You can also use react-native-autoscroll-flatlist#readme

For more detail you can read here wants-to-autoscroll-flatlist-in-react-native