onEndReached 在 Flatlist 问题中 [英] onEndReached in Flatlist issue

查看:49
本文介绍了onEndReached 在 Flatlist 问题中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将平面列表包含在视图中,那么如果我删除封闭的视图 onEndReached 根本不会触发,我的 onEndReached 将无限触发.

If I enclose the flatlist in a View then my onEndReached triggers infinitely if I remove the enclosing View onEndReached is not triggered at all.

 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>
    );
}

而我的 distanceFromEnd 在触发时取值为 0 , 960,1200 .它说明什么?我正在使用 react-native 0.47.2

And my distanceFromEnd takes values like 0 , 960,1200 when it is trigerred. What does it indicate? I'm using react-native 0.47.2

推荐答案

这是因为封闭的 标签.有时将 react-native 标签与 native-base 标签嵌入会导致此类问题.我用 View 标签替换了内容和容器标签,现在它工作正常.

It was because of the enclosing <Content> tag. Sometimes embedding react-native tags with native-base tags causes such issues. I replaced the content and container tag with View tags and now it works fine.

这篇关于onEndReached 在 Flatlist 问题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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