machadogj / react-native-carousel-control

React Native Carousel control with support for iOS and Android
MIT License
247 stars 55 forks source link

updating value list don't take effect #10

Closed SamindaVidanaPathirana closed 8 years ago

SamindaVidanaPathirana commented 8 years ago
<View style={styles.carouselWrapper}>
                            <Carousel
                                pageStyle={{ alignItems: 'center', justifyContent: 'flex-end' }}
                                ref="cardCarausel"
                                sneak={this.state.sneak}
                                onPageChange={(val) => { this._onCardChange(val); }}
                            >
                                {this.state.sliderValueList}
                            </Carousel>
 </View>

This is how i'm including the Carousel to my screen, and upon a certain action i'm deleting an object and updating the "state.sliderValueList" value. But that doesn't seem to update the Carousel, the item is visible till i close the screen and load it back. Requires an urgent feedback.

Thanks

machadogj commented 8 years ago

hi @SamindaPathiranaJadoPado, just tested this in ios and android, and seems to be working. Here's my code:

  state = {
    words: [
      'foo',
      'bar'
    ]
  };

componentDidMount() {
    setTimeout(()=>{
      this.setState({
        words: [ 'foo', 'wiz' ]
      });
      setTimeout(()=>{
        this.setState({
          words: [ 'foo' ]
        });
      }, 3000);
    }, 3000);
  }
//...
render() {
    const pages  = this.state.words.map(w => <Text key={w}>{w}</Text>);
    return (
      <View style={styles.container}>
        <Carousel pageStyle={ {backgroundColor: "white", borderRadius: 5} } initialPage={ 1 }>
          { pages }
        </Carousel>        
      </View>
    );
  }

If you still have this problem, let me know if you can share a bit more code.

SamindaVidanaPathirana commented 8 years ago

Thanks @machadogj managed to figure it out.