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

Scrolling on android appears to get stuck between views unless moved slowly

Open droplessjake opened this issue 2 years ago • 20 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?

(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

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

Android

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

I have confirmed this by building the android app with NODE_ENV=production in my env file, yes.

Environment

Environment: React: 17.0.1 React native: 0.64.2 react-native-snap-carousel: 3.9.1

Target Platform: Android (12.5.3)

Expected Behavior

Swiping between views on Android should snap to the next view when released.

Actual Behavior

If I swipe with some (pretty normal) momentum, the carousel will get stuck between 2 pages, and not call the onSnapToItem method. If I swipe slowly and release about halfway, it perfectly snaps perfectly to the next page. I am aware of the performance issues on android and have tried many props/settings and fixes found in various places on the internet and in the issues here, apologies if I've missed something very common.

Reproducible Demo

(Paste the link to a Snack example in which the issue can be reproduced. Please follow the guidelines for providing a Minimal, Complete, and Verifiable example.)

Steps to Reproduce

These are the current settings after all my efforts.

          <Carousel
            scrollEnabled={calendarState === CalendarState.Open}
            firstItem={prevMonths}
            data={monthData}
            sliderWidth={calendarWidth}
            itemWidth={calendarWidth}
            inactiveSlideOpacity={0.5}
            inactiveSlideScale={0.8}
            inactiveSlideShift={0}
            removeClippedSubviews={false}
            lockScrollWhileSnapping={isAndroid}
            enableMomentum={false}
            disableIntervalMomentum
            enableSnap
            onSnapToItem={onMonthChanged}
            renderItem={renderItem}
          />

https://user-images.githubusercontent.com/83917938/140102710-343fc1d4-5cc4-450a-8041-dd1ebec5324f.mp4

I am using the carousel to create a calendar, each page is a "month" containing rows of weeks, containing 7 days, there is a lot of elements here when you consider we have potentially 42 "days" per month/page and in my case, up to 7 months at a time....

droplessjake avatar Nov 03 '21 16:11 droplessjake

exactly same problem

hammlee avatar Nov 04 '21 09:11 hammlee

Same issue here!

droplessjordan avatar Nov 04 '21 11:11 droplessjordan

Found this library react-native-anchor-carousel which is based off/inspired by this one, but seems to be more refined and lightweight and doesnt have these issues. (and is being actively supported). Would recommend it instead to anyone who finds this thread and needs a simple solution. 👍

droplessjake avatar Nov 04 '21 13:11 droplessjake

I think it's an issue caused by the RN version. I downgraded the version from 0.64.1 to 0.63.4 and it didn't happen anymore.

hammlee avatar Nov 05 '21 07:11 hammlee

Hi, as it said in their guide, you should put those props

...
enableMomentum={false}
decelerationRate={0.9}
...

Hope it helps. This is how I fix this problem

Isaccobosio avatar Nov 08 '21 14:11 Isaccobosio

@droplessjake Can you please try with the latest not published v4 betta version of this library? Just put "react-native-snap-carousel": "git+https://github.com/meliorence/react-native-snap-carousel.git#59fa8950eeb8446124454ab3e2711038066115bb" in your package.json and install node dependencies.

Romick2005 avatar Nov 17 '21 20:11 Romick2005

@Romick2005 thanks for the fix. My carousel in android kept jumping to one specific index on fast scroll. This seems to have handled the buggy scroll snap in android. However, i noticed a few things.

I'm using the default style of the carousel, with 7 cards on a loop:

  1. Before, user scroll always moves 1 card at a time (which is what i need and want). With b4 beta version, it jumps 2 or 3 cards/items on fast scroll and 1 card/item on slow scroll. Are there some props I should set so that any scroll (fast or slow) will move the cards/items just one at a time?
  2. Callback onBeforeSnapToItem is not called anymore. Callback onSnapToItem still works though. Was onBeforeSnapToItem affected by the change?

I already tried putting the following props:

  enableMomentum={false}
  decelerationRate={'fast'}

janetranada avatar Dec 06 '21 10:12 janetranada

@janetranada

  1. I cannot spot any properties for slow/fast scroll in the source, but I think you can modify _getActiveItem method that is use to calculate nextActiveItem based on user action scroll distance.
  2. Yep those method where removed. But I am using force back to the required next active slide index like this.carouselRef.current.snapToItem(index). For my particular case, it is ok to slide from first slide to second and then do validation. If validation not passed I do programatically slide back using snapToItem.

Romick2005 avatar Dec 07 '21 07:12 Romick2005

yes, react native 0.63.4 is ok,but 0.66.3 is broken it is react native version problem

Bruce-Ming avatar Jan 27 '22 08:01 Bruce-Ming

It's still not functioning properly on Android with 0.66.3

richard-grilla avatar Mar 24 '22 15:03 richard-grilla

Not sure if this helps anyone, but I did an edit to the Carousel.js, line 567 which made it at least useable. I removed the centerOffset.

if (this._positions[lastIndex] && center> this._positions[lastIndex].end) {

richard-grilla avatar Mar 24 '22 15:03 richard-grilla

@Romick2005 thanks for the fix. My carousel in android kept jumping to one specific index on fast scroll. This seems to have handled the buggy scroll snap in android. However, i noticed a few things.

I'm using the default style of the carousel, with 7 cards on a loop:

  1. Before, user scroll always moves 1 card at a time (which is what i need and want). With b4 beta version, it jumps 2 or 3 cards/items on fast scroll and 1 card/item on slow scroll. Are there some props I should set so that any scroll (fast or slow) will move the cards/items just one at a time?
  2. Callback onBeforeSnapToItem is not called anymore. Callback onSnapToItem still works though. Was onBeforeSnapToItem affected by the change?

I already tried putting the following props:

  enableMomentum={false}
  decelerationRate={'fast'}

I think it's late but it may help other people. For beta6, you can use disableIntervalMomentum to jump item by item even if you swipe fast.

jobberma avatar Apr 15 '22 13:04 jobberma

Hi, as it said in their guide, you should put those props

...
enableMomentum={true}
decelerationRate={0.9}
...

Hope it helps. This is how I fix this problem

This works for me. Thank you

syedtehrimabbas avatar May 19 '22 06:05 syedtehrimabbas

facing same issue

SMKH-PRO avatar Jul 10 '22 17:07 SMKH-PRO

I had the same issue I solved by adding pagingEnabled and it worked well on android and ios

johnny-washswat avatar Feb 14 '23 05:02 johnny-washswat

All of the solutions are not work for me.. if i scroll it quickyly, android will getting stuck and autoPlay will not work until i scroll it back manually

"react-native": "0.67.3", "react-native-snap-carousel": "3.9.1",

Iamivan1996 avatar Mar 01 '23 06:03 Iamivan1996

Having the same issue:

"react-native": "0.67.5", "react-native-snap-carousel": "^3.9.1",

dsound-zz avatar Sep 15 '23 16:09 dsound-zz

It is recommended to use the react-native-reanimated-carousel library. The current library seems to be no longer maintained.

Bruce-Ming avatar Sep 19 '23 05:09 Bruce-Ming

I had the same issue I solved by adding pagingEnabled and it worked well on android and ios

This works for me 🚀, Thanks @johnny-washswat

Abdullah-Sheikh avatar Feb 22 '24 08:02 Abdullah-Sheikh

I had the same issue I solved by adding pagingEnabled and it worked well on android and ios

@johnny-washswat Thanks! 🔥 That's tottally what I need!

tGulevich avatar Feb 27 '24 10:02 tGulevich