React Native:如果我清除 Listview 数据源,则刷新控件不可用

React Native: Refresh Control not available if I clear the Listview data source

当我将数据源设置为我的列表视图时,刷新控件(下拉刷新)工作得很好。如果数据源为空,我无法下拉刷新列表视图。

我的列表视图如下所示:

                <View contentContainerStyle={{flex: 1}}>
                    <ListView
                        style={styles.container}
                        dataSource={this.state.dataSource}
                        renderRow={(data) => <NotificationRow {...data}/>}
                        enableEmptySections={true}
                        refreshControl={
                            <RefreshControl
                                refreshing={this.state.refreshing}
                                onRefresh={this._onRefresh.bind(this)}
                                tintColor="#ff0000"
                                title="Loading..."
                                titleColor="#ffffff"
                                colors={['#ffffff']}
                                progressBackgroundColor="#1976D2"
                            />
                        }
                    />
                </View>

即使数据源是 empty/null,我是否需要为 Listview 或任何其他方式设置任何道具来启用下拉刷新列表视图?

我正在寻找此功能,因为这是我第一次从异步存储加载数据。在下拉刷新时,我清除存储并获取新数据。

当我在 phone 而不是模拟器上测试应用程序时发现了这一点。即使数据源为空,列表视图始终存在。在我的例子中,列表视图开始于文本视图在红线结束的地方。

您需要使用 prop 调用 refreshing={true} 并完成该过程,如果有新数据则独立您需要设置 refreshing={false} 以通知列表您没有更多数据并隐藏加载指示器。

render() {
    return (
      <ListView
        refreshControl={
          <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh.bind(this)}
          />
        }
        ...
      >
      ...
      </ListView>
    );