【问题标题】:How do I fix null is not an object React Native Splash Screen如何修复 null 不是对象 React Native Splash Screen
【发布时间】: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


【解决方案1】:

运行后react-native run-ios

当我使用的 react-native 版本支持自动链接时,我发现我正在手动链接 react-native-splash-screen 包。

在运行 react-native unlink react-native-splash-screenreact-native run-ios 之后,这解决了我的问题。

【讨论】:

  • 我的问题类似。我不需要取消链接,但我确实需要 react-native run-ios 步骤来完全刷新模拟器上的应用程序。
【解决方案2】:

我的想法是,您应该在 setTimeout() 函数的回调中调用 SplashScreen.hide() 函数。这里:

componentDidMount() {
    setTimeout(1000, () => SplashScreen.hide());
}

如果这不起作用,请尝试检查 SplashScreen 对象持有什么值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多