Current Behavior:

我试图通过打开视图来更新从服务器获取的列表.当我这样做时,onRefresh不会启动.

我已经在setState函数的回调中设置了GET请求,但这似乎没有任何作用.

Expected Behavior:

打开视图调用onRefresh函数.

代码:

...
  constructor(props) {
    super(props);
    this.state = {
      stories: [],
      isFetching: false,
    };
  }
  componentDidMount() { this.fetchData() }
  onRefresh() {
    this.setState({ isFetching: true }, function() { this.fetchData() });
  }
  fetchData() {
    var that = this;
    axios.get('http://192.168.0.13:3000/api/story/get/by/geo')
      .then((res) => {
        that.setState({ stories: res.data, isFetching: false });
        that.props.dispatch(StoryActions.setStories(res.data))
      })
  }
  render() {
    return (
      <ScrollView>
        <FlatList
          onRefresh={() => this.onRefresh()}
          refreshing={this.state.isFetching}
          data={this.state.stories}
          keyExtractor={(item, index) => item.id}
          renderItem={({item}) => (<StoryFeed story={item} id={item.id} /> )}
          />
      </ScrollView>
    )
  }

Version Information

react 本机:0.45.0

node :7.4.0

推荐答案

与React Native有关的问题.当嵌套在ScrollView:Issue ticket:https://github.com/facebook/react-native/issues/14756中时,FlatList似乎没有检测到onRefresh

React-native相关问答推荐

如何在使用嵌套的堆栈导航器在选项卡之间导航后弹出到堆栈顶部?

在第二次加载时仅将本机应用程序设置为状态

axios 在react native 中给出 [AxiosError: Network Error]

_react2.default.PropTypes.function 未定义

在向后滑动时执行操作(react-navigation )

ReactJS 应用多种内联样式

react-navigation中的React-native android后退按钮

在 React Native 上为 android 创建自定义 UI 组件,如何向 JS 发送数据?

React Native React 导航标题按钮事件

从组件的 style属性中获取 CSS 属性值

如何从 React Native 应用程序打开 Google Play store ?

使用 React Navigation 制作离开屏幕的动画

使用 applicationIdSuffix 时 React Native 应用程序不会启动

如何使用 Expo 在真实的 iOS 设备上运行应用程序?

React Native 从导航堆栈中清除上一个屏幕

ListView 和 FlatList 有什么区别?

对未计算文件的本机Bundle sha-1 做出react(无法从assets index.android.bundle 加载脚本)

如何设置样式属性以填充剩余空间?

ReactNative Flatlist - RenderItem not working

React Native 项目,有时使用 expo start 获得连接 ECONNREFUSED 127.0.0.1:19001