react-native - 在 ScrollView onEndReached 内 react Native FlatList 从未调用过

标签 react-native react-native-flatlist

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

平面 list :

<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 也从未调用过。

如何解决这个问题?

最佳答案

实际上你不需要使用 ContentScrollView 因为 FlatList 有 ListFooterComponentListHeaderComponent
如果您确实需要在 ScrollView 中使用 FlatList,则将样式和内容 contentContainerStyle 添加到您的 ScrollView 中,或者如果您使用 native-base,则在 Content

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

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

关于react-native - 在 ScrollView onEndReached 内 react Native FlatList 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319922/

相关文章:

javascript - Navigator 和 AsyncStorage react native

react-native - 无法读取this.props.navigation.dispatch()中未定义的属性“dispatch”

node.js - 如何将 React.js/React Native Apps 连接到 Azure 应用服务的单个后端实例?

android - 保护 SD 卡并通过应用程序访问它

javascript - 如何在 React Native 中动态更新 FlatList?

unit-testing - react-navigation-hooks : How to test useFocusEffect

firebase - 从 Firestore 检索/处理图像 URL - React Native

react-native - 从状态中删除项目后平面列表不重新渲染

react-native - 是否有可在 Android 和 IOS 上使用的 native recyclerview (react-native)