snapToItem doesn't change the current index "quick enough"
See original GitHub issueBug 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
When adding the following properties it started to work:
Can someone please explain why it works now? Someone else also appears to have this problem: https://github.com/archriss/react-native-snap-carousel/issues/541#issuecomment-514165668
On Android the whole snapToItem is not working.