react-native-snap-carousel icon indicating copy to clipboard operation
react-native-snap-carousel copied to clipboard

Removing last item from carousel results in an empty space (Android)

Open danvickers opened this issue 5 years ago • 11 comments

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

Bug report

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

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

Yes as far as possible.

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

Android

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

Yes - it presents in a live version of our app

Environment

react-native-snap-carousel: 3.8.4 [email protected] Android 9

Expected Behavior

When removing the last item from the data I expected the carousel to display the next available item as it does with start and middle list items and as it does on iOS.

Actual Behavior

An empty space is displayed

Reproducible Demo

https://snack.expo.io/@danjvee/react-native-snap-carousel-item-remove-bug---android

Steps to Reproduce

  1. Preview the code on Android
  2. Scroll right to the last item in the carousel.
  3. Tap the item delete button
  4. Observe the empty space

danvickers avatar Nov 20 '19 12:11 danvickers

I have the same issue, a quick workaround I used was scrolling to the previous item after deleting.

DiegoMac95 avatar Dec 02 '19 20:12 DiegoMac95

Hi, I have the same problem, can you explain more your solution @DiegoMac95 please

askemeline avatar Mar 11 '20 15:03 askemeline

Hello, we have the same issue here, could you provide us any detailed informations ?

ghost avatar Mar 11 '20 16:03 ghost

@askemeline When I delete an element from the carousel, I also use snapToPrev method to scroll to the previous element, manually doing what the carousel does in iOS, that deletes the empty space.

DiegoMac95 avatar Mar 11 '20 16:03 DiegoMac95

Thanks for your response but I don't really understand when you use it without the onPress. I would like that android do it automatically when I delete the last element :/

askemeline avatar Mar 11 '20 17:03 askemeline

@askemeline that's why you need to add the reference like this

<Carousel
  // LIKE THIS
  ref={(c) => { this._carousel = c; }}
/>

// now you can call it wherever you have access to the reference of the carousel
deleteAndSnap = () => {
     deleteElement();
     this._carousel.snapToPrev(); 
}

You don't actually need to use 'onPress', you can call the method anywhere in your component using that reference

DiegoMac95 avatar Mar 11 '20 17:03 DiegoMac95

Thanks for your answer but I have still the bug :/

askemeline avatar Mar 12 '20 10:03 askemeline

My bad, is working, many thanks @DiegoMac95 :)

askemeline avatar Mar 12 '20 13:03 askemeline

What can I do if I have enableSnap={false}?

AlexReusC avatar Jan 14 '21 22:01 AlexReusC

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

dohooo avatar Oct 08 '21 05:10 dohooo

Any updates on this? Still facing this issue.

wnikola avatar Nov 28 '23 16:11 wnikola