React-native-swiper: Example method scrollBy

Created on 9 Feb 2017  路  3Comments  路  Source: leecade/react-native-swiper

Hello,
I am a beginner in react-native and I found your swiper very powerful and easy-to-use! Thank you 馃槂
Now I'd like to do a method that will autoscroll to another index when I touch a button (not with autoplay).
I think it's possible with the scrollBy(index,animated) method but I can't find an example that uses it.
I guess I should pass the swiper as a parameter (props) to the view component but I really don't understand how could I...

Here is the important part of my code

export default class swiper extends Component {
    render() {
        return (
            <Swiper
                showsPagination={false}
                showsButtons={false}
                loop= {false}
                index={0}>
                <Swiper
                    horizontal={false}
                    showsPagination={false}
                    showsButtons={false}
                    loop= {false}
                    index={0}>
                    <Tastr typeConnection={ConnectMusic} />
                    <Tastr typeConnection={ConnectMusic} />
                </Swiper>
                <Tastr typeConnection={ConnectShows} />
            </Swiper>
        )
    }
}

I need to go from ConnectMusic to ConnectedMusic when i touch a button.

Best regards,
Hadrien

Most helpful comment

You have to create a reference to the swiper to access its method.
add to the swiper of which you want to use scrollBy
ref={(swiper) => {this._swiper = swiper;}}
then add this to the button you have to click to scroll the swiper
onPress={() => this._swiper.scrollBy(1)}

All 3 comments

You have to create a reference to the swiper to access its method.
add to the swiper of which you want to use scrollBy
ref={(swiper) => {this._swiper = swiper;}}
then add this to the button you have to click to scroll the swiper
onPress={() => this._swiper.scrollBy(1)}

You have to create a reference to the swiper to access its method.
add to the swiper of which you want to use scrollBy
ref={(swiper) => {this._swiper = swiper;}}
then add this to the button you have to click to scroll the swiper
onPress={() => this._swiper.scrollBy(1)}

GREAT Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chetanparakh picture chetanparakh  路  3Comments

wrannaman picture wrannaman  路  3Comments

gwhite-dayspring picture gwhite-dayspring  路  3Comments

kylehagler picture kylehagler  路  3Comments

agzuniverse picture agzuniverse  路  3Comments