flastList onEndReached 多次调用 | 不停调用

ListView / flastList onEndReached 多次调用

解决办法

  1. Add onMomentumScrollBegin prop to your FlatList declaration.
        <FlatList
          data={this.props.data}
          onEndReached={...}
          onEndReachedThreshold={0.5}
          ...
          onMomentumScrollBegin={() => { this.onEndReachedCalledDuringMomentum = false; }}
        />
  1. Modify your onEndReached callback to trigger data fetching only once per momentum.
  onEndReached = () => {
    if (!this.onEndReachedCalledDuringMomentum) {
      this.props.fetchData();
      this.onEndReachedCalledDuringMomentum = true;
    }
  };