Is there a way of changing the index programatically? Say by stating the currently viewed 'slide' as a property of the state: state = { currentSelectedSlide: 1 }?
I tried doing Swiper.scrollBy(1); and got an error scrollBy is not a function.
Are you correctly assigning the ref? I'm using this.swiper.scrollBy(1); and it's working as intended.
@ttargo1 throws swiper is not a function
@mitajunior make sure you're assigning swiper as the swiper's ref.
js
<Swiper
ref={(swiper) => {this.swiper = swiper;}}
>
Just wanted to leave an update here for people using React-Native with hooks and functional components. You need to use "current" to access the scrollBy function.
const swiper = useRef(null)
<Swiper ref={swiper}>
<View>
<Button onPress={() => swiper.current.scrollBy(1)} title="Page 1" />
</View>
<View>
<Button onPress={() => swiper.current.scrollBy(1)} title="Page 2" />
</View>
</Swiper>
Most helpful comment
Just wanted to leave an update here for people using React-Native with hooks and functional components. You need to use "current" to access the scrollBy function.