Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android doesn't fire snap event for the last item when scrolled all the way #681

Closed
5 tasks done
dbilgin opened this issue Apr 9, 2020 · 14 comments
Closed
5 tasks done

Comments

@dbilgin
Copy link

dbilgin commented Apr 9, 2020

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

This is a bug report, I have seen this but I am doubtful that it's the same thing.

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?

It's only on Android.

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

Yes, tried it with an assembled apk.

Environment

React: 16.8.6
React native: 0.60.5
react-native-snap-carousel: 3.9.0
Android: Seems to be all Android versions

Expected Behavior

When I swipe to the very last item I expect the snap events to fire even if I didn't stop my finger immediately when the swipe was in place and that I wouldn't have to nudge the carousel again to make it work.

Actual Behavior

reproduce

Reproducible Demo

Here is the demo

Steps to Reproduce

I think the steps are fairly simple

  1. Create a carousel smaller than the width of the screen with three views in it.
  2. Move to the middle view.
  3. Move to the third view starting to hold it from the very right of the screen and not the third view itself and swipe it to the very left.
@dbilgin dbilgin changed the title Android doesn't snap to the last item when scrolled all the way Android doesn't fire snap event for the last item when scrolled all the way Apr 9, 2020
@vincentzierigen
Copy link

vincentzierigen commented Apr 23, 2020

Having the same issue with RN 0.60.4

@CoenWarmer
Copy link

Having the same issue (RN 0.61.4). Any workaround available before a fix is deployed?

@dbilgin
Copy link
Author

dbilgin commented May 7, 2020

I couldn't find any workarounds so far, would actually appreciate it very much, if someone did.

@CoenWarmer
Copy link

@dbilgin Haven't found one yet, unfortunately.

@CoenWarmer
Copy link

I believe the same happens on Android when scrolling past the first item. The callback isn't fired then either.

@nitaking
Copy link

My solution:

  1. Add empty data ([data, data, {}]]
  2. if (lastIndex === 2 ) { this.onEnd() }

@luka-iyarn
Copy link

luka-iyarn commented May 13, 2020

Have the same issue with both first and last items
This worked for me:
enableMomentum={Platform.OS === 'android'}

@dbilgin
Copy link
Author

dbilgin commented May 13, 2020

@luka-iyarn that doesn't fix it for me unfortunately.

@CoenWarmer
Copy link

@bd-arc thank you for your work on the library! It is by far the best carousel library for RN out there.

Is this particular bug on Android something that you want to address in version 4, or is this something that can be fixed in the current 3.x approach?

@bd-arc
Copy link
Contributor

bd-arc commented Aug 6, 2020

Hey guys! Did any of you tried the 4.x beta version? (the latest one being 4.0.0-beta.5)

Since the carousel has been heavily updated, it might now work out-of-the box. Scroll events on Android have always been unreliable, but I'm hoping that the improved logic will fix your issue.

Let me know!

@dbilgin
Copy link
Author

dbilgin commented Aug 6, 2020

@bd-arc thank you for your response! I just tried it on my project again with 4.0.0-beta.5, somehow it got worse :( Now it doesn't snap to the second one even.

@roybselim
Copy link

I ended up creating a custom logic on 'onScroll'

      onScroll={(event) => {
        const currentOffset = event.nativeEvent.contentOffset.x;
        if (onPress && answers && Array.isArray(answers)) {
          if (currentOffset === 0) {
            onPress(answers[0]);
          }
          if (currentOffset >= ITEM_WIDTH * (answers.length - 1) - 5) {
            onPress(answers[answers.length - 1]);
          }
        }
      }}

@dohooo

This comment was marked as spam.

@dbilgin
Copy link
Author

dbilgin commented Mar 8, 2022

Just gonna go with FlatList.

@dbilgin dbilgin closed this as completed Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants