bra*_*dos 21 react-native expo
Unhandled promise rejection: Error: No native splash screen registered for given view controller. Call 'SplashScreen.show' for given view controller first.
当我第一次启动该应用程序时,仅在我的 ios 模拟器上收到以下警告。不在我的 ios 物理设备或 Android 模拟器上。我用于expo-splash-screen我的闪屏。这是我可以忽略的事情还是我需要解决它,因为我不知道如何解决它。启动画面似乎加载良好。这是一个错误吗expo-splash-screen?我按照世博会的教程进行设置。
警告:
[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
Run Code Online (Sandbox Code Playgroud)
索引.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 />;
}
Run Code Online (Sandbox Code Playgroud)
应用程序.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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
这个问题是因为你正在使用AppLoading,这个组件目前在iOS上有这个bug。
您可以解决此问题,在错误解决之前避免使用此组件,另一种方法是创建一个像 Splashscreen 这样的屏幕并替换<AppLoading />为<MyAwesomeSplashScreen />
...或者以一种粗鲁和懒惰的方式(糟糕的用户体验)只需更改<AppLoading />为<View />
| 归档时间: |
|
| 查看次数: |
20762 次 |
| 最近记录: |