Skip to content

Instantly share code, notes, and snippets.

@hungdev
Last active February 23, 2020 14:04
Show Gist options
  • Select an option

  • Save hungdev/d7dbd3f1ea1ea3b2679bfbccccbc2c86 to your computer and use it in GitHub Desktop.

Select an option

Save hungdev/d7dbd3f1ea1ea3b2679bfbccccbc2c86 to your computer and use it in GitHub Desktop.
Pull to refresh

đặt cái props này ở trong scrollview ( view bao ngoài cùng ) hoặc trong flatlist

refreshControl={
            <RefreshControl
              refreshing={this.state.refreshing}
              onRefresh={this._onRefresh.bind(this)}
            />
          }

like this:

<FlatList
  data={dataPost}
  extraData={this.props}
  refreshControl={
    <RefreshControl
      refreshing={this.state.refreshing}
      onRefresh={() => this._onRefresh()}
    />}
  keyExtractor={item => item.id}
  renderItem={({ item, index }) => (
    <ItemList
      item={item}
      indexCard={index}
      onRemoveCard={item => this.onRemoveCard(item)} />
  )}
/>
  async _onRefresh() {
    this.setState({ refreshing: true })
    await this.props.getPosts()
    this.setState({ refreshing: false })
  }

if we have loadmore, we need change to:

  _onRefresh() {
   this.setState({
     page: this.state.page + 1,
     refreshing: true
   }, () => {
     this.props.getPosts(this.state.page)
     this.setState({ refreshing: false })
   });
 }

  constructor(props) {
   super(props);
   this.state = {
     refreshing: false
   };
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment