ReactReact Native 导航安全区问题

az31mfrm  于 2023-02-09  发布在  React
关注(0)|答案(5)|浏览(200)

我更新了我的安卓项目react-navigation was 3.x,移动到5.x,决定实现必要的变化,但它不想工作,从React导航页面复制的例子,但仍然显示相同的错误,有人知道这里的问题在哪里吗?因为我谷歌了一半的互联网,不能找到解决方案
我的包裹

{
  "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)
hfyxw5xn

hfyxw5xn1#

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

qlzsbp2j

qlzsbp2j2#

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

bnlyeluc

bnlyeluc3#

我有一个只适用于Android的解决方案。那就是你只需要在你的终端中按照下面的步骤操作。
[your project path]\> cd android并输入。
然后,如果您在PowerShell中,只需键入下面的命令。
[your project path]\android\> ./gradlew clean
如果你是在cmd键入下面的命令.
[your project path]\android\> gradlew clean
重启你的react原生项目。

sqxo8psd

sqxo8psd4#

npm i react-native-gesture-handler@1.0.16 -D -E
tct7dpnv

tct7dpnv5#

打开您的MainApplication.java并添加代码顶部;

import com.th3rdwave.safeareacontext.SafeAreaContextPackage;

然后在getPackages()函数中添加以下代码;

packages.add(new SafeAreaContextPackage());

相关问题