react-native-viewpager icon indicating copy to clipboard operation
react-native-viewpager copied to clipboard

This does not work when I request image data from a remote location.

Open luojinghui opened this issue 8 years ago • 3 comments

` constructor(props) { super(props);

this.state = {
  jnSlides: [],
  dataSource: null
};

} componentDidMount() { this._isMounted = true; let uri = 'RotationImages/banner'; let _this = this;

this.req = jnRequest.getData(uri, (res) => {
  var dataSource = new ViewPager.DataSource({
    pageHasChanged: (p1, p2) => p1 !== p2,
  });
  var setIt = dataSource.cloneWithPages(res);

  if (this._isMounted) {
    _this.setState({
      jnSlides: res,
      dataSource: setIt
    })
  }
})

} _renderPage(data, pageID) { console.log(data); return ( <Image source={data.image} style={styles.slide1}/> ); } render() { return ( <View style={styles.wrapper}>

      <ViewPager
          style={{height:130}}
          dataSource={this.state.dataSource}
          renderPage={this._renderPage}
          isLoop={true}
          autoPlay={true}/>
    </View>
)

} `

then, have error: Cannot read property 'pageIdentities of null how can i resolve?

luojinghui avatar Dec 14 '16 14:12 luojinghui

start by setting dataSource = [] instead of null in constructor. I don't know if it'll work if you do as I say, but I'm pretty sure it fails if you don't.

Fulla avatar May 29 '17 22:05 Fulla

it isn't work. please write a simple can you?

lizhuoyuan avatar Jun 12 '17 09:06 lizhuoyuan

Why don't you do this:

var dataSource = new ViewPager.DataSource({
    pageHasChanged: (p1, p2) => p1 !== p2,
  });

In the constructor and then assign it to state.

Then in the appropriate section of componentDidMount try this:

if (this._isMounted) {
    _this.setState({
      jnSlides: res,
      dataSource: dataSource.cloneWithPages(res)
    })
  }

Hope it works

mateofd avatar Jun 20 '17 21:06 mateofd