使用带有ReactNative的Android上的ListView,onEndReached没有按预期工作

时间:2016-03-25 11:01:23

标签: android listview react-native

我正在尝试使用ListView平台上的React-Native列出Android中的数百个项目。 react-native的版本为0.22。这是我的ListView组件:

<ListView dataSource={dataSource}
                      onEndReached={onEndReached}
                      renderRow={this.renderRow.bind(this)}/>

当页面加载时,我按如下方式检索批量数据和fullfill数据源:

onEndReached(page) {
    let {dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})} = this.state;

    return myService.search({page})
        .then(newRows => {
            this.setState({
                dataSource: dataSource.cloneWithRows(newRows),
                page: page
            });
        });
}

renderRow(row){console.log(row.id); // This is printed for all rows regardless of whether it is displayed on the screen or not}

基本上发生的是,onEndReached功能是通过轻微滑动或有时甚至没有任何手势触发的。我认为只有在呈现给dataSource的所有行时才会调用此函数。奇怪的是,我看到我的所有行都调用了renderRow函数,而不仅仅是屏幕上显示的行。我尝试使用scrollRenderAheadDistance,但无济于事。

任何人都可以指出我做错了什么?

1 个答案:

答案 0 :(得分:1)

问题是我的[31, 45, 6], [31, 83, 38] # this is the first classical anti-diagonal in the first matrix ListView之下,它正在打破它的行为。删除ScrollViewListView后,它开始按预期工作。

相关问题