Fai*_*hou 6 react-native react-native-flatlist
我的容器是一个滚动视图,里面是一个平面列表,它从服务器加载数据。
平面列表:
<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;
}}
/>
Run Code Online (Sandbox Code Playgroud)
这handleLoadMore是:
handleLoadMore = () => {
Log('handleLoadMore fired!');
if (!this.onEndReachedCalledDuringMomentum) {
// fetch data..
this.onEndReachedCalledDuringMomentum = true;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是handleLoadMore从未被调用和onMomentumScrollBegin也从未被调用。
怎么解决这个问题呢?
实际上你不需要使用ContentorScrollView因为 FlatList 具有ListFooterComponentandListHeaderComponent
如果您确实需要在内部使用 FlatList ScrollView,则将样式和内容 contentContainerStyle 添加到您的容器样式中ScrollView,或者如果您使用 native-base,则在Content
<ScrollView
...
style={{flex: 1}}
contentContainerStyle={{flex: 1}}
...
/>
Run Code Online (Sandbox Code Playgroud)
然后,如果您想在 FlatList 循环之外使用标头组件。然后在Flatlist里面使用ListHeaderComponent={() => <SomeHeader />。
| 归档时间: |
|
| 查看次数: |
7580 次 |
| 最近记录: |