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

Is there an equivalent to onBeforeSnapToItem to get the index before fully snapping to a page? #762

Open
zaidqureshi95 opened this issue Jan 17, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@zaidqureshi95
Copy link

Hello,

First, thank you for the amazing work on this library!

I have a question about event handling for snapping behavior in the carousel. In libraries like react-native-snap-carousel, there is a prop called onBeforeSnapToItem, which provides the index of the page we are about to snap to before the snap animation is complete.

I noticed that this library has the onSnapToItem prop, but it triggers only after the snap is fully completed.

Is there any existing functionality or workaround in the library that allows me to detect the target index before the snapping animation completes? This would help in scenarios where I need to trigger updates or preload data while the user is swiping, but before the snap is finalized.

If this feature doesn’t exist yet, are there plans to implement something similar, or is there a recommended way to achieve this behavior?

Thank you for your time and help!

@zaidqureshi95 zaidqureshi95 added the enhancement New feature or request label Jan 17, 2025
Copy link

dosubot bot commented Jan 17, 2025

Hey @zaidqureshi95! I'm here to help you with any questions or issues you have. Let's work together to tackle this challenge!

A similar open issue discusses achieving functionality similar to onBeforeSnapToItem. The suggested solution involves using the customAnimation prop to predict the index during the animation. This method allows you to run a function when the animation value exceeds a certain threshold, updating a variable to ensure it only runs once. This way, you can predict the index while the animation is running, without waiting for the onSnapToItem prop to provide an index. However, it's important to validate the predicted index with the actual index to avoid discrepancies in future index changes. You can find more details in the issue discussion [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants