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

onSnapToItem callback not triggering consistently

Open odusseys opened this issue 9 years ago • 15 comments

Version 3.2.2 I am trying to use the onSnapToItem callback to track the index of the carousel. My code is :

<Carousel
          style={{ flex: 1 }}
          ref={c => {
            if (c) this._carousel = c;
          }}
          data={this._cardData}
          renderItem={this._makeCard}
          sliderWidth={sliderWidth}
          itemWidth={itemWidth}
          inactiveSlideOpacity={0.0}
          onSnapToItem={index => {
            console.warn(index);
            this.setState({ index });
          }}
        />

The callback is not consistently called. It is consistently called when calling this._carousel.snapToNext/Prev, but not always when swiping (in particular almost never when swiping left).

odusseys avatar Sep 19 '17 12:09 odusseys

Hi @odusseys,

Have you read this note from the doc? Also, are you currently testing on Android with dev mode enabled?

bd-arc avatar Sep 19 '17 13:09 bd-arc

Your first link is not working for me, it's just redirecting me to the repo. Also I am testing on the iOS simulator.

On Tue, 19 Sep 2017, 15:31 Benoît Delmaire [email protected] wrote:

Hi @odusseys https://github.com/odusseys,

Have you read this note https://github.com/archriss/react-native-snap-carousel/#unreliable-callbacks from the doc? Also, are you currently testing on Android with dev mode enabled https://github.com/archriss/react-native-snap-carousel/#android-performance ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/archriss/react-native-snap-carousel/issues/153#issuecomment-330539828, or mute the thread https://github.com/notifications/unsubscribe-auth/AHf-PrhSB03IyEufpKAIJllc4AlhIHfBks5sj8I-gaJpZM4PcVVF .

odusseys avatar Sep 19 '17 14:09 odusseys

Yep, the first link is supposed to redirect you to the "Unreliable callbacks" section of the doc.

Make sure to take a look at that section as well as the callbackOffsetMargin prop and let me know if that helps.

bd-arc avatar Sep 19 '17 15:09 bd-arc

Just saw that, thanks. I tried

  • enabling JS debugging : no change
  • setting a higher value for callbackOffsetMargin (tried 10, 50, 500), no change

odusseys avatar Sep 19 '17 16:09 odusseys

Hum, that's odd. I'm using the latest version in a store app and it works flawlessly.

Can you try:

  • Running the example? If the pagination works, then the callback is also working.
  • Deploy a production version of your app on a real device with an alert() callback for example?

bd-arc avatar Sep 19 '17 16:09 bd-arc

@odusseys I think I've been able to reproduce the issue. Can you confirm that it happens only when you do a long swipe instead of a short swipe?

bd-arc avatar Sep 20 '17 08:09 bd-arc

@odusseys Indeed, I made a mistake while refactoring the callback mechanism. This commit fixes the issue.

Can you confirm that it works for you?

bd-arc avatar Sep 20 '17 09:09 bd-arc

@bd-arc I've got the same problem. It seems that this only happens with long swipe.

wildvalcom avatar Sep 20 '17 15:09 wildvalcom

@wildvalcom Have you tried the commit referenced in my latest comment?

bd-arc avatar Sep 20 '17 15:09 bd-arc

Has this been released to npm or should I link the repo directly ?

odusseys avatar Sep 20 '17 16:09 odusseys

This hasn't been published yet; I prefer letting you try it first and let me know if you experience any side effect.

See this note about using a specific commit.

bd-arc avatar Sep 20 '17 16:09 bd-arc

I had the issue describe by OP. It seems to go away when you add this config properties

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

peterchibunna avatar Sep 20 '17 22:09 peterchibunna

As previously stated, I've already pushed a commit for that. You can try it this way:

"react-native-snap-carousel": "https://github.com/archriss/react-native-snap-carousel#edd98f3"

@odusseys @wildvalcom @peterchibunna Does it solve the issue for you?

bd-arc avatar Sep 21 '17 07:09 bd-arc

@bd-arc thanks mate, works good for me.

wildvalcom avatar Sep 21 '17 07:09 wildvalcom

@wildvalcom Perfect! Thanks for letting me know.

The fix is now available in version 3.2.3.

bd-arc avatar Sep 21 '17 08:09 bd-arc