meliorence / react-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
BSD 3-Clause "New" or "Revised" License
10.36k stars 2.29k forks source link

AutoScroll stops when clicked and scrolled the entire screen vertically #823

Open suhask-iprogrammer opened 3 years ago

suhask-iprogrammer commented 3 years ago

I have a horizontal carousal at the bottom of my screen and when I scroll the screen vertically by holding the click on the carousal autoscroll stops and when I scroll the carousal manually the carousal again starts autoscrolling.

Need to solution for this.

ZeroPie commented 3 years ago

Can reproduce: Seems it happens when the carousel is inside a ScrollView. I am not sure what exactly is triggering it, try scrolling upwards and downwards repeatedly and tapping on the items and at some point it will stop autplaying https://snack.expo.io/@alejkun/snap-bug

ZeroPie commented 3 years ago

Anyways! A solution for reliable autplay after user Interactions: Don't use autoplay and snapToNext programmatically:

const carouselRef = useRef(null);

  useEffect(() => {
    const interval = setInterval(() => {
      carouselRef?.current?.snapToNext();
    }, 3000);
    return () => clearInterval(interval);
  }, []);

  <Carousel
          ref={carouselRef}
          data={data}
          renderItem={renderNewsStage}
          itemWidth={deviceWidth}
          sliderWidth={deviceWidth}
          onSnapToItem={(index) => setCarouselCurrentIndex(index)}
          enableMomentum={false}
          lockScrollWhileSnapping
          loop
        />
suhask-iprogrammer commented 3 years ago

@ZeroPie this solved my problem...thanks :smiley:

suhask-iprogrammer commented 3 years ago

@ZeroPie in the above solution images are auto-scrolling while we are scrolling the images manually by swiping, due to which carousal seems to be flickering.... any solution to lock the scroll while snapping on this. How to pause interval while snapping manually.

dohooo commented 3 years ago

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2