'React native flatlist horizontall autoscroll

How to stop autoscroll after touching the flatlist? Now it scrolls always and can`t be stop. Or how to continue autoscroll from the index where i stopped touching scroll

 const ref = useRef();
  let currentSlide = 0;
  let intervalTime = 4000;

  const goToNextPage = () => {
    if (currentSlide >= banners.length - 1) currentSlide = -1;
    ref.current.scrollToIndex({
      index: ++currentSlide,
      animated: true,
    });
  };

   useEffect(() => {
    setInterval(goToNextPage, intervalTime);
  }, []);


return(
 <FlatList
          data={banners}
          keyExtractor={item => item.id}
          renderItem={renderItem}
          scrollEventThrottle={16}
          contentContainerStyle={{paddingHorizontal: 12}}
          showsHorizontalScrollIndicator={false}
          horizontal
          snapToInterval={bannersWidth + 24}
          decelerationRate={'fast'}
          bounces={false}
          ref={ref}
          getItemLayout={(data, index) => ({
            length: bannersWidth + 24,
            offset: (bannersWidth + 24) * index,
            index,
          })}
        />
)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source