meliorence / meliorence/react-native-snap-carousel
snapToItem doesn't change the current index "quick enough"
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report
This is a bug report
Have you followed the required steps before opening a bug report?
(Check the step you've followed - put an x character between the square brackets ([]).)
- I have read the guidelines regarding bug report.
- I have reviewed the documentation in its entirety, including the dedicated documentations 📚.
- I have searched for existing issues and made sure that the problem hasn't already been reported.
- I am using the latest plugin version.
- I am following the issue template closely in order to produce a useful bug report.
Have you made sure that it wasn't a React Native bug?
Yes
Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?
Only tested on Ios
Is the bug reproductible in a production environment (not a debug one)?
No
Environment
Environment:
React Native: https://github.com/expo/react-native/archive/sdk-34.0.1.tar.gz
React-native-snap-carousel: ^3.7.5
Target platform: iOS (12.0) -> EXPO
(Write your answer here.)
Expected Behavior
When programmatically snapToItem it will change the current index in the callback of the renderItem function with the correct value.
(Write what you thought would happen.)
See above.
When programmatically changing the snapToItem proving an index doesn't change the currentIndex or doesn't change the currentIndex quick enough in the carousel. So when the render function is being called I am receiving an old current Index which is crashing my existing code.
Reproducible Demo
renderFiveHundredFilter = ({item, index}) => {
console.log("CURRENT_INDEX", this._carousel.currentIndex);
^^ this._carousel.currentIndex won't change when an item is pressed. It will remain on 0
return (
<Text onPress={() => {
this._carousel.snapToItem(index);
this.onPrivilegesRangeChange("click", index)
}
} key={`abc_${index}`} style={{color: this._carousel.currentIndex === index ? "gold" : "white", fontFamily: Fonts.heavy, fontSize: Fonts.small}}>{item.name}</Text>
)
}
Steps to Reproduce
- Create a simple Carousel
- Change to a snap item programmatically using snapToItem callback function
- See if the currentIndex of the carousel is being received in the render function with the correct result.
Contributor guide
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
Reproduce the issue with the provided renderFiveHundredFilter example and a React Native Carousel, focusing on programmatic snapToItem calls and the currentIndex value during rendering. Done means currentIndex reflects the selected item when the render callback runs without crashing dependent code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100