React-native-swiper: scrollBy / The method does not work correctly

Created on 4 Apr 2017  路  1Comment  路  Source: leecade/react-native-swiper

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>

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;

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);

}

}
}

>All comments

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);

}

}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tokict picture tokict  路  3Comments

kliuj picture kliuj  路  3Comments

nomoreboredom picture nomoreboredom  路  3Comments

diegolmello picture diegolmello  路  3Comments

gwhite-dayspring picture gwhite-dayspring  路  3Comments