meliorence / meliorence/react-native-snap-carousel

How does onBeforeSnapToItem determine the destination offset of the native momentumScroll?

Open
#570 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

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

Question

How does onBeforeSnapToItem determine the destination offset of the native momentumScroll?

I've happily been using this module in an app, but as the amount of content and UI complexity in the app grew larger, we unfortunately had to drop this module in favor of a raw <FlatList snapToInterval={... instead, to ensure a decent performance on older devices.

However, I really miss the onBeforeSnapToItem event, which has no equivalent on the <ScrollView> or <FlatList> components.

onMomentumScrollEnd is fired after the scrolling animation finishes, and onScroll does not tell anything about the snapping destination offset.

I tried digging into the code of this module, but it's not completely clear to me where it's determining the destination offset and thereby calculates the item index that it's going to snap to. Basically, the code does 100 other things as well, so it's very hard to keep track of what determines the data sent to onBeforeSnapToItem ...

I hope someone with better overview of the code base can come up with some hints - thank you in advance :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Carousel.js at the linked line and trace how the native momentum scroll destination becomes the item index passed to onBeforeSnapToItem. Compare that flow with the surrounding carousel scroll handling. Done means documenting the offset and index calculation clearly enough to explain the event payload.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.