onSnapToItem callback not triggering consistently
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).
Hi @odusseys,
Have you read this note from the doc? Also, are you currently testing on Android with dev mode enabled?
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 .
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.
Just saw that, thanks. I tried
- enabling JS debugging : no change
- setting a higher value for callbackOffsetMargin (tried 10, 50, 500), no change
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?
@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?
@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 I've got the same problem. It seems that this only happens with long swipe.
@wildvalcom Have you tried the commit referenced in my latest comment?
Has this been released to npm or should I link the repo directly ?
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.
I had the issue describe by OP. It seems to go away when you add this config properties
enableMomentum={false}
enableSnap={true}
decelerationRate={'fast'}
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 thanks mate, works good for me.
@wildvalcom Perfect! Thanks for letting me know.
The fix is now available in version 3.2.3.