leecade / leecade/react-native-swiper
state.index goes off the rail, internally inconsistent with state.offset.x
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
I've written the following for debugging and attempt at correction. I observed that during quick swiping horizontally through my 10 horizontal child Scrollviews under react-native-swiper during heavy cpu use (rendering in said child Scrollviews), oftentimes index would go off the rails and be wrong.
My debugging code:
const onMomentumScrollEnd = (e, state, context) => {
let index = Math.round(state.index)
let offsetIndex = Math.round(state.offset.x / Dimensions.get('window').width - 1)
if (index != offsetIndex) {
console.log(`>>> Swiper.onMomentumScrollEnd offsetIndex ${offsetIndex} doesn't agree with index ${index}:`, state, context)
index = offsetIndex
}
}
index, when wrong, would always be smaller than it should be. offsetIndex would always be correct, corresponding to the correct Scrollview with data displayed within for that actual index.
This is obviously a problem as a wrong index loses the correct placement of child Scrollviews, and wrong display of the pager dots.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the onMomentumScrollEnd callback and trace how state.index and state.offset.x are updated during rapid horizontal swipes, especially with heavily rendering child ScrollViews. Reproduce the mismatch under heavy CPU use and verify that the index, displayed child ScrollView, and pager dots remain aligned with the offset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100