我完全按照这个步骤来做: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,但似乎什么都不起作用。
发布于 2020-07-12 14:51:30
在运行react-native run-ios之后
当我使用的react-native版本支持自动链接时,我发现我手动链接了react-native-splash-screen包。
在运行react-native unlink react-native-splash-screen和react-native run-ios之后,这解决了我的问题。
发布于 2020-07-12 14:57:51
我认为应该在setTimeout()函数的回调中调用SplashScreen.hide()函数。这里:
componentDidMount() {
setTimeout(1000, () => SplashScreen.hide());
}如果这不起作用,请尝试检查SplashScreen对象包含的值是什么。
https://stackoverflow.com/questions/62840008
复制相似问题