获取完成后如何在本机反应中导航到另一个屏幕

how to navigate to another screen in react native when fetch is done

我是 React Native 的新手,正在尝试创建我的第一个应用程序。所以我有一个问题:

我有 2 个屏幕(使用反应导航)。在第一个屏幕上,有一个带有微调器的应用程序徽标渲染(来自本机基础)并同时获取到服务器。而且我只需要在获取结束并处理响应时导航到另一个屏幕。我在 react-navigation 文档中找到的所有内容都是带有按钮的解决方案,但这不是我的情况。此外,我不想使用 ActivityIndi​​catorIOS(应用程序对于 Android 应该是正确的)。

请帮助我了解我应该怎么做?

非常感谢!

只需在 fetch 的 then 回调中调用 navigate 函数或在 catch 中适当处理错误。

react-navigation gets the navigation prop. You can use the navigate 中的每个屏幕都可以导航到任何屏幕。像这样

class FirstScreen extends React.Component {
  static navigationOptions = {
    title: 'First',
  }
  componentDidMount(){
    const {navigate} = this.props.navigation;
    navigate('Second');
    fetch('http://apiserver').then( (response) => {
      navigate('Second');
    });
  }
  render() {
    return (
      <AppLogo />
    );
  }
}

const AppNavigator = StackNavigator({
  First: {
    screen: FirstScreen,
  },
  Second: {
    screen: SecondScreen,
  },
});