反应本地反应导航SafeArea问题

时间:2020-07-11 13:17:39

标签: android reactjs react-native react-navigation

我更新了我的Android项目react-navigation was 3.x,移至5.x,决定实施必要的更改,但它不起作用,从react-navigation页面复制了示例,但仍然显示相同的错误,有人知道这里的问题在哪里吗?我在互联网上搜索了一半,却找不到解决方法

我的package.json:

{
  "name": "BusinessCard",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.7.0",
    "@react-navigation/stack": "^5.7.0",
    "react": "^16.13.1",
    "react-native": "^0.63.0",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-reanimated": "^1.9.0",
    "react-native-safe-area-context": "^3.1.1",
    "react-native-safe-area-view": "^1.1.1",
    "react-native-screens": "^2.9.0"
  },
  "devDependencies": {
    "@babel/core": "^7.10.4",
    "@babel/runtime": "^7.10.4",
    "babel-jest": "^24.9.0",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  }
}

我复制的代码:

import 'react-native-gesture-handler';
import * as React from 'react';
import { StyleSheet, View, Text, TouchableHighlight } from "react-native";
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

function HomeScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

错误:

Invariant Violation: requireNativeComponent: "RNCSafeAreaProvider" was not found in the UIManager.

This error is located at:
    in RNCSafeAreaProvider (at SafeAreaContext.tsx:74)
    in SafeAreaProvider (at SafeAreaProviderCompat.tsx:42)
    in SafeAreaProviderCompat (at StackView.tsx:432)
    in GestureHandlerRootView (at GestureHandlerRootView.android.js:31)
    in GestureHandlerRootView (at StackView.tsx:431)
    in StackView (at createStackNavigator.tsx:82)
    in StackNavigator (at App.js:27)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:376)
    in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
    in ThemeProvider (at NavigationContainer.tsx:90)
    in ForwardRef(NavigationContainer) (at App.js:26)
    in App (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
[Sat Jul 11 2020 15:11:50.561]  ERROR    Invariant Violation: requireNativeComponent: "RNCSafeAreaProvider" was not found in the UIManager.

This error is located at:
    in RNCSafeAreaProvider (at SafeAreaContext.tsx:74)
    in SafeAreaProvider (at SafeAreaProviderCompat.tsx:42)
    in SafeAreaProviderCompat (at StackView.tsx:432)
    in GestureHandlerRootView (at GestureHandlerRootView.android.js:31)
    in GestureHandlerRootView (at StackView.tsx:431)
    in StackView (at createStackNavigator.tsx:82)
    in StackNavigator (at App.js:27)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:376)
    in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
    in ThemeProvider (at NavigationContainer.tsx:90)
    in ForwardRef(NavigationContainer) (at App.js:26)
    in App (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)

3 个答案:

答案 0 :(得分:1)

在较新版本的React Navigation中,我们必须手动安装react-native-safe-area甚至react-native-screens。我已经通过sudo npm install react-native-safe-areasudo npm install react-native-screens解决了类似的问题。然后从我的Android清除应用数据,然后重新安装该应用。打开新的终端(Ubuntu 20.04 LTS),然后运行npm start。试试这个,可能会有所帮助。

答案 1 :(得分:0)

您要尝试:cd ios && pod安装&& cd .. 然后关闭应用程序,关闭所有终端并重建您的应用程序。希望能帮到您。

答案 2 :(得分:0)

我只有android解决方案。那就是您只需要按照以下步骤在您的终端中即可。

[your project path]\> cd android并输入。

然后, 如果您使用的是PowerShell,只需在下面键入命令。

[your project path]\android\> ./gradlew clean

如果您在cmd中,请输入以下命令。

[your project path]\android\> gradlew clean

然后重新启动您的本机项目。