React native 在平面列表问题中实现了ONEDREACHED
如果我将平面列表包含在一个视图中,那么如果我移除了包含的视图,则我的onEndReached将无限触发React native 在平面列表问题中实现了ONEDREACHED,react-native,react-native-flatlist,React Native,React Native Flatlist,如果我将平面列表包含在一个视图中,那么如果我移除了包含的视图,则我的onEndReached将无限触发 render() { return ( <Root> <Container> <Content> <View> {this.state.listView && (
render() {
return (
<Root>
<Container>
<Content>
<View>
{this.state.listView && (
<FlatList
data={this.state.variants}
keyExtractor={this._keyExtractor}
onEndReachedThreshold={0.5}
onEndReached={({ distanceFromEnd }) => {
console.log(
"on end reached ",
distanceFromEnd
);
this.loadMore();
}}
numColumns={1}
renderItem={({ item, index }) => (
<CatalogRow
item={item}
in_wishlist={this.state.in_wishlist}
toggleWishlist={() =>
this.toggleWishlist(item.title)
}
listView={this.state.listView}
/>
)}
/>
)}
</View>
</Content>
</Container>
</Root>
);
}
render(){
返回(
{this.state.listView&&(
{
console.log(
“到达终点”,
距离末端
);
这是loadMore();
}}
numColumns={1}
renderItem={({item,index})=>(
此.toggleWishlist(项.标题)
}
listView={this.state.listView}
/>
)}
/>
)}
);
}
当触发mydistanceFromEnd
时,其值为0,9601200。它表明了什么?
我使用的是react native 0.47.2,我会这样使用它:
handleMore = () => {
// fetch more here
};
<FlatList
onEndReached={this.handleMore}
/>
handleMore=()=>{
//在这里多拿些
};
这是因为带有
标记。有时,将react本机标记嵌入本机基标记会导致此类问题。我用视图
标记替换了内容和容器标记,现在它工作正常。我对RN 0.52也有同样的问题
看起来像是因为平面列表找不到高度。所以他找不到名单的末尾
通过使用flex=1的视图包装平面列表进行修复
<View style={{flex: 1}} > <Flatlist /> <View>
我对react native 0.50.3也有同样的问题 如果要使用
ONEDREACHED,则不能在
中使用,因为Flatlist找不到高度
改用
,我不认为你的代码中有什么真正的错误。只需尝试将react本机版本更新为最新版本,然后进行检查。他们的实现中可能有一个bug,将在最新版本中修复。非常有用。。。正确答案!!我有一个文章屏幕,我想在用户到达文章正文末尾时加载评论。我如何处理这个问题?现在我在scrollview中有一个平面列表,它一直在无限期地触发ONEDREACHED。