加载时多次响应本机嵌套ListView onEndReached触发器 [英] React Native nested ListView triggers onEndReached multiple times on loading

查看:81
本文介绍了加载时多次响应本机嵌套ListView onEndReached触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

<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>

我已经查看了react native的github中的问题列表.包装了ScrollView时,onEndReached不能正常工作. 我尝试了所有发现的方法,但没有成功.

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.

我只需要FlatList显示数据.两个列表分别滚动不是我想要的.这就是为什么我需要ScrollView.看来筑巢是不可避免的. 有办法吗?

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?

推荐答案

这是我的固定列表的外观,并且工作正常.

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} />} />

这篇关于加载时多次响应本机嵌套ListView onEndReached触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆