Hello. The method does not work if you click on the index 0. If I click on index 0, 1 and 2 will stop working. If I click 2 times on 1 or 2, then the slider will go to the desired slide. But the zero index does not work at all. Tell me please, what could be the problem?
<Swiper
ref={(swiper) => {this.swiper = swiper;}}
showsButtons={false}
width={500}
height={500}
showsPagination={false}
index={0}
loop={true} >
<View>
<Text>One</Text>
</View>
<View>
<Text>Two</Text>
</View>
<View>
<Text>Three</Text>
</View>
</Swiper>
<Text onPress={()=>{this.swiper.scrollBy(0, true)}}>One</Text>
<Text onPress={()=>{this.swiper.scrollBy(1, true)}}>Two</Text>
<Text onPress={()=>{this.swiper.scrollBy(2, true)}}>Three</Text>
I did this method:
onClickScroll(index){
let currentIndex = this.state.index;
if(currentIndex !== index) {
let resultSlide = undefined;
let countSlides = this.state.itineraryDaysListItem.length;
if(index > currentIndex && index !== countSlides)
{
resultSlide = index - currentIndex;
this.swiper.scrollBy(resultSlide, true);
}
else if(index>currentIndex && index === countSlides)
{
resultSlide = currentIndex+1;
this.swiper.scrollBy(resultSlide, true);
}
else if(index < currentIndex && index !== 0){
resultSlide = (currentIndex - index) * (-1);
this.swiper.scrollBy(resultSlide, true);
}
else if(index < currentIndex && index === 0){
resultSlide = currentIndex * (-1);
this.swiper.scrollBy(resultSlide, true);
}
}
}
Most helpful comment
I did this method:
onClickScroll(index){
let currentIndex = this.state.index;
if(currentIndex !== index) {
let resultSlide = undefined;
let countSlides = this.state.itineraryDaysListItem.length;
}
}