react-native-looped-carousel icon indicating copy to clipboard operation
react-native-looped-carousel copied to clipboard

How to get current page?

Open quentinpaden opened this issue 8 years ago • 3 comments

quentinpaden avatar Jun 22 '17 01:06 quentinpaden

Hi, you can use getCurrentPage().

Example:

setCarouselRef = (ref) => {
    this.carousel = ref
}

getCurrentPage() {
  return this.carousel && this.carousel.getCurrentPage()
}

render() {
    return (
      <View style={{ flex: 1 }} onLayout={this._onLayoutDidChange}>
        <Carousel
          delay={2000}
          style={this.state.size}
          autoplay
          pageInfo
          onAnimateNextPage={(p) => console.log(p)}
          ref={this.setCarouselRef}
        >
          <View style={[{ backgroundColor: '#BADA55' }, this.state.size]}><Text>1</Text></View>
          <View style={[{ backgroundColor: 'red' }, this.state.size]}><Text>2</Text></View>
          <View style={[{ backgroundColor: 'blue' }, this.state.size]}><Text>3</Text></View>
        </Carousel>
      </View>
    );
  }

viktorsec avatar Jun 22 '17 10:06 viktorsec

Thank you so much, you are awesome!

quentinpaden avatar Jun 22 '17 11:06 quentinpaden

If you don't mind me asking, how would you put that method into a text component? It keeps telling me it's unidentified.

quentinpaden avatar Jun 22 '17 12:06 quentinpaden