Closed sergioribeiro closed 8 years ago
Hi @sergioribeiro the onPageChange returns the index of the page, and you should have the array you passed to the carousel to retrieve the page. Is that what you mean? What do you need it for?
I need to know when the user slides to the last page.
@sergioribeiro you can know that with the index passed in onPageChange. See this sample:
state = {
words: [
'foo',
'bar'
]
};
handleOnPageChange(pageIndex) {
if (pageIndex === this.state.words.length - 1) {
console.log('we reached the end!');
}
}
render() {
const pages = this.state.words.map(w => <Text key={w}>{w}</Text>);
return (
<View style={styles.container}>
<Carousel
initialPage={ 1 }
pageStyle={ {backgroundColor: 'white', borderRadius: 5} }
onPageChange={ this.handleOnPageChange.bind(this) }
>
{ pages }
</Carousel>
</View>
);
}
Let me know if that helps.
Thank you very much!
Welcome!
<Carousel onPageChange={ self.myFunction() }> { array } </Carousel>