【发布时间】:2020-07-10 18:08:02
【问题描述】:
我完全按照以下说明进行操作:https://www.npmjs.com/package/react-native-splash-screen 以及观看经过相同步骤的 youtube 视频。
我的代码是:
import * as React from 'react';
import SplashScreen from 'react-native-splash-screen';
import HomePage from './src/Home';
import {navigationRef} from './RootNavigation';
import * as RootNavigation from './RootNavigation.js';
const Stack = createStackNavigator();
export default class App extends React.Component {
componentDidMount() {
setTimeout(1000);
SplashScreen.hide();
}
render() {
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomePage}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
}
应用程序完全按照应有的方式运行,但只有 web 我删除了 componentDidMount 方法。我设置 SplashScreen.hide(); 的行是导致错误的原因。
我得到的错误是:
TypeError: null is not an object (evaluating '_reactNativeSplashScreen.default.hide')
This error is located at:
in App (at renderApplication.js:45)
in RCTView (at AppContainer.js:109)
in RCTView (at AppContainer.js:135)
in AppContainer (at renderApplication.js:39)
componentDidMount
App.js:47:4
我已尝试进行手动安装,确保已安装 react-native-splash-screen 并运行 npm install,但似乎没有任何效果。
【问题讨论】:
-
你在用expo吗?
-
不,我没有使用 expo。
-
你可以删除你的 setTimeout 调用。这将在 1 秒后不运行。
-
会做的,我试过这个代码有/没有那个调用,仍然是同样的错误。
-
你更新你的
MainActivity.java了吗?
标签: javascript android ios react-native