且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

反应原生“onViewableItemsChanged"滚动动态数据时不起作用

更新时间:2023-01-25 17:25:57

我自己解决了这个问题.问题是因为我试图用 Ajax 填充数据.为了解决这个问题,我从 Parent 组件运行请求并将其传递到 props并且在类的构造函数中,如果为我的数组填充了状态.

I solved the problem myself. The problem was because of I was trying to populate the data with Ajax. To solve that I ran the request from the Parent component and passed it in props and inside the constructor of the class if filled the state for my array.

您应该考虑的另一件事是您应该在 View 中渲染整个 FlatList.

Another thing that you should consider is that you should render the whole FlatList inside a View.

这是我的最终代码:

export default class TimeLine extends Component {
constructor(props) {
    super(props);
    this.viewabilityConfig = {
        minimumViewTime: 500,
        viewAreaCoveragePercentThreshold: 60,
    };
}
render() {
    const {timeline} = this.state;
    return (
        <View style={styles.container}>
            <FlatList
                data={timeline}
                renderItem={({item}) => this.renderTimelineList(item)}
                viewabilityConfig={this.viewabilityConfig}
                onViewableItemsChanged={({viewableItems}) => this.handleViewableItemsChanged(viewableItems)}
            />
        </View>
    );

};
}