javascript - 如何修复 null 不是对象 React Native Splash Screen

标签 javascript android ios react-native

我完全按照以下说明操作: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/

相关文章:

javascript - Javascript 中选定文本的节点名称

android - 从 url android 下载 docx 文件

ios - 如何在实际设备上调试 Apple Watch 应用程序?

ios - 打开 iPhone/iPad 设置面板

ios - 谷歌登录 : Unable to disconnect iOS app

javascript - TinyMCE onchange_callback 不工作

javascript - 将光标放在 keyup 上文本的末尾

javascript - 如果值相同则更新代码

android - 包含 TableLayouts 的 fragment 的 ViewPager 加载缓慢 :

android - 无法在 Android 中显示 Toast