React-native-swiper: A way to swipe by action

Created on 11 Oct 2016  路  5Comments  路  Source: leecade/react-native-swiper

i am looking to have the ability to scroll to another slide by an action i made myself.

like, i want to add some button that when i press it, it will swipe to 5th slide.
how can i do it?

Most helpful comment

I'm not sure if it's the best option, but you can give the swiper component a reference and then use the scollBy method.

render() {
  return (
     <Swiper ref='mySwiper'  />
     <Button onClick={this._jumpSlide}>Jump</Button>
  )
}

_jumpSlide = () => {
  this.refs.mySwiper.scrollBy( n ); // where n is the number of slides to move
};

All 5 comments

I'm not sure if it's the best option, but you can give the swiper component a reference and then use the scollBy method.

render() {
  return (
     <Swiper ref='mySwiper'  />
     <Button onClick={this._jumpSlide}>Jump</Button>
  )
}

_jumpSlide = () => {
  this.refs.mySwiper.scrollBy( n ); // where n is the number of slides to move
};

It's the only solution that worked for me, thanks @andrantis .

Cool!, thank you!!!
Ir worked perfectly from the first time! 馃憤

"this.refs" is deprecated, what is the alternative?

this approach helped me a lot. Thanks for sharing the solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndriiBoiko picture AndriiBoiko  路  3Comments

kylehagler picture kylehagler  路  3Comments

gwhite-dayspring picture gwhite-dayspring  路  3Comments

itinance picture itinance  路  3Comments

nomoreboredom picture nomoreboredom  路  3Comments