在 ScrollView onEndReached 内反应 Native FlatList 从未调用过 [英] React Native FlatList inside ScrollView onEndReached never called

查看:50
本文介绍了在 ScrollView onEndReached 内反应 Native FlatList 从未调用过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的容器是一个滚动视图,里面是一个平面列表,它从服务器加载数据.

My container is a scrollview and inside it is a flatlist, which load data from server.

平面列表:

<VirtualizedList
  ListEmptyComponent={<NoData />}
  data={data}
  getItem={(items, index) => items.get(index)}
  getItemCount={(items) => items.size}
  keyExtractor={(item, index) => String(index)}
  renderItem={this._renderItem}
  refreshControl={
     <RefreshControl
       refreshing={loading}
       onRefresh={this._onRefresh.bind(this)}
     />
  }
  onEndReached={this.handleLoadMore}
  onEndReachedThreshold={0.1}
  onMomentumScrollBegin={() => {
    Log('onMomentumScrollBegin fired!')
    this.onEndReachedCalledDuringMomentum = false;
  }}
/>

哪个 handleLoadMore 是:

handleLoadMore = () => {
  Log('handleLoadMore fired!');
  if (!this.onEndReachedCalledDuringMomentum) {
    // fetch data..
    this.onEndReachedCalledDuringMomentum = true;
  }
}

问题是 handleLoadMore 从未调用过,onMomentumScrollBegin 也从未调用过.

The problem is the handleLoadMore never called and the onMomentumScrollBegin also never called.

如何解决这个问题?

推荐答案

实际上你不需要使用 ContentScrollView 因为 FlatList 有两个 ListFooterComponentListHeaderComponent

Actually you don't need to use Content or ScrollView as FlatList has both ListFooterComponent and ListHeaderComponent

如果你真的需要在 ScrollView 中使用 FlatList,然后将样式和内容 contentContainerStyle 添加到你的 ScrollView 或者如果你使用 native-base,在 中内容

In case you really need to use FlatList inside ScrollView, then add style and content contentContainerStyle to your ScrollView or if you use native-base, inside the Content

<ScrollView
  ...
  style={{flex: 1}}
  contentContainerStyle={{flex: 1}}
  ...
/>

然后,如果您想在 FlatList 循环之外使用标题组件.然后使用 ListHeaderComponent={() => 在 Flatlist 中.

Then if you want to use header component out of FlatList loop. Then use ListHeaderComponent={() => <SomeHeader /> inside Flatlist.

这篇关于在 ScrollView onEndReached 内反应 Native FlatList 从未调用过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆