问题
Here's the code:
<ScrollView>
{ tree.myPoiComments.CommentInfo && tree.myPoiComments.CommentInfo.length>0 &&
<FlatList
data={tree.myPoiComments.CommentInfo}
keyExtractor = {(item, index) => item.CommentId}
ListHeaderComponent = {() => <View>
<Text style={styles.listHeader}>My Comments</Text>
</View>}
renderItem= {({item}) => <CommentItem comment={item} owner={1} />}
/>
}
{ tree.poiComments.CommentInfo && tree.poiComments.CommentInfo.length>0 &&
<FlatList
data={tree.poiComments.CommentInfo}
keyExtractor = {(item, index) => item.CommentId}
onEndReachedThreshold={1}
onEndReached={(info) => {
alert(JSON.stringify(info));
} }
extraData = {this.state}
bounces={false}
ListHeaderComponent = {() => <View>
<Text style={styles.listHeader}>People's Comments</Text>
</View>}
renderItem= {({item}) => <CommentItem comment={item} owner={0} />}
/>
}
</ScrollView>
I've went through the issue list in github of react native. onEndReached just won't work properly when there is a ScrollView wrapped. I tried everything I find, none worked.
I only need the FlatList displaying data. Two lists scroll separately is not what I want. That's why I need the ScrollView. It seems the nesting construction is inevitable. Is there a way around?
回答1:
This is how my flat list looks like and it works fine.
https://github.com/facebook/react-native/issues/16067
<FlatList
onEndReachedThreshold={ 0.5 }
onEndReached={ () => this.onEndReached() }
refreshing= { false }
onRefresh={ ()=> {
this.refetchData()
} }
data={this.state.data}
renderItem={({ item }) => <Item id={item.key} />} />
来源:https://stackoverflow.com/questions/48940820/react-native-nested-listview-triggers-onendreached-multiple-times-on-loading