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

When nesting carousel, can't snapToItem with ref of inner carousels #789

Open catanon opened 3 years ago

catanon commented 3 years ago

Is this a bug report, a feature request, or a question?

Might not be a bug but rather a usage different than intended.

Have you followed the required steps before opening a bug report?

(Check the step you've followed - put an x character between the square brackets ([]).)

Have you made sure that it wasn't a React Native bug?

Yes. This is related to the looping behavior of Carousel.

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

It happens on both.

Is the bug reproductible in a production environment (not a debug one)?

I couldn't find production mode on Snack.

Environment

Environment: Expo: 39.0.5 React: 16.13.1 React native: 0.63.2 react-native-snap-carousel: 3.9.1

Happens to Expo 40 with react-native-snap-carousel 4.0.0-beta.6 too

Target Platform: Android (whichever version Snack used) iOS (14)

Expected Behavior

I'm nesting horizontal carousels inside a vertical carousel to create a grid system. Both dimensions allow looping. There will be buttons that let users jump to a specific screen.

Actual Behavior

It jumps to the correct row but not the correct column. (This happens to a different example from the demo below) After you jump, without changing the column, change the row in one direction and stop before it loops back to the wanted row. Peeking the wanted row, you might see the correct column. But it will change when you actually move to that row.

Reproducible Demo

https://snack.expo.io/@jloq/react-native-snap-carousel-nested-carousel Press the text to jump. Every text jumps to 1, 1. I believe the problem is that enabling looping made the innerRef in line 34 different than the snapped item of line 33. I already have a workaround of disabling looping in the outer carousel but looping is still preferable.

Steps to Reproduce

  1. Nest horizontal carousels inside a vertical carousel. Enable looping in all of them.
  2. Obtain the refs of them.
  3. Try to snap to a different row and column.
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