【问题标题】:Expo: How to change the splash image programmatically?Expo:如何以编程方式更改启动图像?
【发布时间】:2020-04-10 19:03:57
【问题描述】:

我有一个 React Native Expo app.json 如下:

{
  "expo": {
    "name": "Awesome App",
    "splash": {
      "image": "./assets/images/splash.jpg",
    },
  ...
}

在我的应用程序中,我希望允许用户从图像列表中选择一个图像(从服务器加载),并且该图像将在下次用户启动应用程序时显示在启动屏幕中。

我如何在 Expo 中做到这一点?

【问题讨论】:

    标签: expo splash-screen


    【解决方案1】:

    您将使用反应导航。只需在 stackNavigator 中添加 splashScreen

    export default StackNavigator({
      SplashScreen: { screen: SplashScreen },
      AuthScreen: { screen: AuthScreen },
      MainNavigator: { screen: MainNavigator }
    }, {
      headerMode: 'screen',
      navigationOptions: {
        header: { visible: false }
      }
    })
    

    添加超时。在我的情况下

    componentDidUpdate () {
      if (this.state.isAppReady) {
        if (this.state.isLoggedIn) {
          this.props.navigation.navigate('MainNavigator');
        } else {
          this.props.navigation.navigate('AuthScreen');
        }
      }
    }
    

    您可以在渲染中更改图像。

    【讨论】:

    • 这种方式适合Expo加载我们的App后使用。
    猜你喜欢
    • 2015-07-13
    • 1970-01-01
    • 2011-04-18
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    相关资源
    最近更新 更多