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.86k stars 329 forks source link

Page rendering is incorrect when changing the scrolling direction. #568

Closed blackazaru closed 6 months ago

blackazaru commented 8 months ago

Describe the bug Page rendering is incorrect when changing the scrolling direction

To Reproduce Steps to reproduce the behavior:

  1. Init example with ~10 elements
  2. Begin scrolling to the right, and when you reach the fourth or fifth element, attempt to scroll to the left.

Expected behavior You should see the previous element, but the carousel renders the same one.

Screenshots

https://github.com/dohooo/react-native-reanimated-carousel/assets/6501334/6394f9f0-3c23-44db-ba73-eeb3c548eed9

Versions (please complete the following information):

Smartphone (please complete the following information):

Additional context

My review indicates that Reanimated's useSharedValue doesn't update the value immediately (scrollEndTranslation). https://github.com/dohooo/react-native-reanimated-carousel/blob/d78784808f1a4d233708561354ca198122cfbb62/src/components/ScrollViewGesture.tsx#L342-L355

Consequently, we encounter an incorrect (previous) value in the endWithSpring function, which triggers the incorrect direction. https://github.com/dohooo/react-native-reanimated-carousel/blob/d78784808f1a4d233708561354ca198122cfbb62/src/components/ScrollViewGesture.tsx#L138-L142

benforsrup commented 8 months ago

Probably the same issue as described in #535

robioconic commented 8 months ago

Also experiencing this issue!

ckanissatran commented 7 months ago

Creating a patch with the changes @nmassey created here: https://github.com/dohooo/react-native-reanimated-carousel/pull/574 fixed this bug for me on ^4.0.0-alpha.10

wscullen commented 7 months ago

I'm experiencing this in alpha.6 and above, for me it look like alpha.5 doesn't exhibit this.

dohooo commented 6 months ago

Solved in https://github.com/dohooo/react-native-reanimated-carousel/releases/tag/v4.0.0-alpha.12