React-native-swiper: How do I switch to an index?

Created on 9 May 2018  路  5Comments  路  Source: leecade/react-native-swiper

I need to switch to a specific index. Is this possible?

The method scrollBy only increases the value of the index.

Most helpful comment

The scrollBy takes a number of slides it should slide to...

If you're on slide 2 - and want to go to slide 3
.scrollBy(1)

If you're on slide 3 - and want to go to slide 2
.scrollBy(-1)

The library really should have a scrollTo(index) method.

All 5 comments

The scrollBy takes a number of slides it should slide to...

If you're on slide 2 - and want to go to slide 3
.scrollBy(1)

If you're on slide 3 - and want to go to slide 2
.scrollBy(-1)

The library really should have a scrollTo(index) method.

@brandoncorbin

That only works if you have 2 slides (You go back and you go next) but how about if you have 6 slides? How exactly to go to the slide you wanted to see?

I have totally no clue on how to do it with many slides. By the way, i use 6 Buttons to manually go to these slides

@Albert0405 the lib requires you to do the math ...

scrollBy(nextSlideIndex - currentSlideIndex)

If user is on slide 2, and you want them to go to slide 6, then the scrollBy will be 4.
6 - 2 = 4

If the user is on slide 6 and you want them to get to slide 2, then the scrollBy would be -4
2 - 6 = -4

@brandoncorbin Can you check my issue please. Regarding with your suggestion above, i dont know how to get the currentSlideIndex

787

@brandoncorbin
OMG, sorry i already fixed it. It was my mistake for putting currentSlideIndex inside the function, it supposed to be outside it. Thank you for your suggestion 馃憤

Check it here #787

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicolabortignon picture nicolabortignon  路  3Comments

commit-master picture commit-master  路  3Comments

itinance picture itinance  路  3Comments

ghost picture ghost  路  3Comments

Liqiankun picture Liqiankun  路  3Comments