React Native 嵌套 ListView 在加载时多次触发 onEndReached

Xor*_* Wu 5 listview nested-lists react-native react-native-flatlist

这是代码:

<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>
Run Code Online (Sandbox Code Playgroud)

我已经浏览了 react native github 中的问题列表。当有 ScrollView 包裹时,onEndReached 将无法正常工作。我尝试了我找到的所有东西,但没有一个奏效。

我只需要 FlatList 显示数据。两个列表分别滚动不是我想要的。这就是为什么我需要 ScrollView。嵌套构建似乎是不可避免的。有办法吗?

Sah*_*tel -1

这就是我的平面列表的样子,而且效果很好。

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} />} />
Run Code Online (Sandbox Code Playgroud)