Hello it will be really nice to have a scrollTo function in Swiper, in my case i want to scroll to view 5 from view 1 and viceversa.
Thanks a lot!
Since it looks like this package isn't getting updated soon... Here's how to implement a hacky "scrollTo" method
// Listen for swiper index changes
let swiperIndex = 0
Swiper.prototype.componentWillUpdate = (nextProps, nextState) => {
swiperIndex = nextState.index
}
class ... {
swiper: Object
render() {
<Swiper ref={(ref) => {this.swiper = ref}}>
...
</Swiper>
<Something onPress={() => {
// Scroll back to a specific index (you may require better logic)
const targetIndex = 0
this.swiper.scrollBy(targetIndex - swiperIndex, true)
}} />
}
}
Most helpful comment
Since it looks like this package isn't getting updated soon... Here's how to implement a hacky "scrollTo" method