我完全按照以下说明操作: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,但似乎没有任何效果。
最佳答案
运行react-native run-ios
后
我发现当我使用的 react-native 版本支持自动链接时,我正在手动链接 react-native-splash-screen 包。
在运行 react-native unlink react-native-splash-screen
然后 react-native run-ios
这解决了我的问题。
关于javascript - 如何修复 null 不是对象 React Native Splash Screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62840008/