dohooo / react-native-reanimated-carousel

🎠 React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)
https://react-native-reanimated-carousel.vercel.app
MIT License
2.72k stars 314 forks source link

scrollTo has incorrect type and is possibly also not working #266

Open AdamGerthel opened 2 years ago

AdamGerthel commented 2 years ago

Describe the bug ICarouselInstance.scrollTo has a TS declaration which doesn't seem to match the documentation. According to TypeScript, scrollTo accepts a TCarouselActionOptions, but according to the documentation, it expects a number:

    /**
     * Use value to scroll to a position where relative to the current position,
     * scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
     */
    scrollTo: (opts?: TCarouselActionOptions) => void;

I've tried using a number, and that didn't work as expected. I've also tried passing an object with an index, { index: 1 } (or equivalent). But neither works as expected.

Expected behavior I expect scrollTo to take a number as parameter as described in the JS comment.

Versions (please complete the following information):

AdamGerthel commented 2 years ago

Update: The typescript annotation is actually wrong for next and prev too. It says (opts?: Omit<TCarouselActionOptions, 'index'>) which seems incorrect since it takes a number parameter.

jhhayashi commented 1 year ago

I'm running into this on v3.0.5 as well. The carousel progresses toward the index, but only makes it about halfway. In other words, if I'm on index 2 and try to scroll to index 1 or 0, the carousel progresses to index 1. If I'm on index 3 and try to scroll to index 0, it scrolls to index 1

jhhayashi commented 1 year ago

After more testing, it seems to work fine when animated is false, but not when animated is true

akshy78695 commented 1 year ago
ref?.current?.scrollTo({
      index: 1,
      animated: true,
    });
altarrok commented 1 year ago

Have the same issue as @akshy78695, can confirm it only happens when animated: true. Please fix this