错误:没有为给定的视图控制器注册本机启动屏幕,对于react-native expo使用启动屏幕

gzszwxb4  于 6个月前  发布在  React
关注(0)|答案(2)|浏览(83)

第一个月
当我第一次启动应用程序时,我只在我的ios模拟器上收到以下警告。不在我的ios物理设备或android模拟器上。我使用expo-splash-screen作为初始屏幕。这是我可以忽略的问题还是我需要解决它,因为我不知道如何解决它。初始屏幕似乎加载正常。这是expo-splash-screen的错误吗?我跟着expo's tutorial设置它。

警告:

[Unhandled promise rejection: Error: No native splash screen registered for given view controller. Call 'SplashScreen.show' for given view controller first.]
at node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
at node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
at node_modules/expo-splash-screen/build/SplashScreen.js:23:17 in hideAsync
at node_modules/expo-splash-screen/build/SplashScreen.js:19:7 in hideAsync
at [native code]:null in callFunctionReturnFlushedQueue

字符串

index.js

import React, { useState, useEffect, useCallback } from 'react';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import { Asset } from 'expo-asset';
import AppLoading from 'expo-app-loading';

import Navigation from './config/Navigation';

export default function App() {
  const [appIsReady, setAppIsReady] = useState(false);

  useEffect(() => {
    async function prepare() {
      try {
        // keep splash screen visible while we fetch resources
        await SplashScreen.preventAutoHideAsync();
        // Pre-load fonts, make any api calls here
        await Asset.loadAsync(require('../assets/IMG_0024.jpg'));
        // Artificially delay for two seconds to simulate a slow loading
        // experience. Please remove this if you copy and paste the code!
        // await new Promise(resolve => setTimeout(resolve, 2000));
      } catch (e) {
        console.warn(e);
      } finally {
        // Tell app to render
        setAppIsReady(true);
      }
    }

    prepare();
  }, []);

  const onLayoutRootView = useCallback(async () => {
    if (appIsReady) {
      // This tells the splash screen to hide immediately! If we call this after
      // `setAppIsReady`, then we may see a blank screen while the app is
      // loading its initial state and rendering its first pixels. So instead,
      // we hide the splash screen once we know the root view has already
      // performed layout.
      await SplashScreen.hideAsync();
    }
  }, [appIsReady]);

  onLayoutRootView();

  if (!appIsReady) {
    return <AppLoading />;
  }

  return <Navigation />;
}

app.json

{
  "expo": {
    "name": "name",
    "slug": "slug",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#fffffb"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["assets/images/*"],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFB"
      }
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}

fgw7neuy

fgw7neuy1#

这个问题是因为你正在使用AppLoading,这个组件目前在iOS上有这个bug。
你可以解决这个问题,避免使用这个组件,直到错误得到解决,一个替代方案是创建一个屏幕像你的启动屏幕,并取代<AppLoading /><MyAwesomeSplashScreen />
.或者以一种粗鲁和懒惰的方式**(糟糕的用户体验)**只需将<AppLoading />更改为<View />

xtupzzrd

xtupzzrd2#

我认为问题是相关的开发菜单,当应用程序安装并首次打开.尝试在生产模式下运行您的项目,当开发菜单禁用:npx expo start --no-dev --minify

相关问题