-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Make sure that onSnapToItem
is triggered AFTER scroll animation's completion
#34
Comments
marginally related to this, inside I noticed this because I'm using <Carousel
ref={(carousel) => { this.carousel = carousel; }}
onSnapToItem={(index) => {
console.log('snap', index, this.carousel.currentIndex);
this.forceUpdate()
}}
>
{screens}
</Carousel>
<CarouselControls
onPress={(page) => this.carousel.snapToItem(page)}
selected={this.carousel ? this.carousel.currentIndex : 0}
length={screens.length}
/>
|
@piuccio Thanks for your feedback! This is pretty strange; I'll take a look at it as soon as possible. |
Some answer about this problem ? |
Hi @joseygordev, are you referring to @piuccio's issue or to the original one? Regarding the former, I should be able to take a look at it in the next few days; regarding the latter, we are still awaiting an evolution of React Native's source code. The issue is still pending 6 months later, without any feedback from RN's team... |
Hi guys, I finally had time to dig into this issue. I can confirm that, sadly, it is deeply related to React Native's implementation. For all the reasons explained in my first post, we can't rely on anything but the Since |
I just had an idea worth trying, which is to rely on slide animation's completion and to combine it with a time threshold to "determine" if scroll has ended. This is clearly far from ideal, but it might still lead to better results than |
@piuccio @joseygordev Version 2.2.1 should resolve your issue with the faulty index. I've completely refactored the way callbacks are handled when momentum is disabled. Let's face it: this is hacky since Make sure to play with the new props |
@bd-arc thank you very much for you attention, component very nice. |
@joseygordev Note that version 2.3.0 handles no-momentum callbacks way better ;-) |
Currently, React Native doesn't provide a callback for the
scrollTo()
method, which is a bummer.The ScrollView component has a prop
onScrollAnimationEnd
, but unfortunately this works on iOS only (even though it is referenced in the Java file). Moreover, a bug currently prevents the callback from being fired with horizontal scrollers.Another lead would be to link the duration of the scroll animation to a timer before firing the callback. Unfortunately,
scrollTo()
doesn't accept a custom duration.An idea might be to activate momentum events on Android and see if
onMomentumScrollEnd
can provide a good enough feedback without impairing performance too much. But this event might not be fired when snapping programatically... Moreover, it is automatically enabled if a momentum callback has been set.ScrollResponder is another lead worth pursuing...
The text was updated successfully, but these errors were encountered: