首页 > 解决方案 > 到达 ListFooterComponent 末尾时调用 React Native FlatList onEndReached

问题描述

我正在使用 aFlatList来显示无限滚动的项目列表。onEndReached使用道具到达列表末尾时会加载更多数据。但是,列表下方是更多使用ListFooterComponent. 这会导致onEndReached在到达页脚末尾时调用,而不是实际列表的末尾。可以稍微配置一下,onEndReachedThreshold但页脚的高度可能会定期变化,所以这不是一个好的解决方案。

<FlatList
    data={[0, 1, 2, 3, 4, 5, 6, 7, 8]}
    renderItem={() => (
       <View style={{ backgroundColor: "#f00", height: 300 }} />
    )}
    ListFooterComponent={
       <View style={{ backgroundColor: "#0f0", height: 3000 }} />
    }
    onEndReached={() => console.log("will be called when end of ListFooterComponent is reached")}
/>

这是一个错误还是应该这样工作?有人有解决方法的想法吗?

标签: react-nativereact-native-flatlist

解决方案


推荐阅读