Zirek
Zirek

Reputation: 523

React native react-navigation SafeArea issue

I updated my android project, react-navigation was 3.x, move to 5.x, decided to implement necessary changes but it doesn't want to work, copied example from react-navigation page but still shows same error, anyone knows where is the problem here? As I googled half of the internet and can't find solution

My 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"
  }
}

My copied code:

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;

And the 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)
[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)

Upvotes: 4

Views: 11376

Answers (6)

Abhitech
Abhitech

Reputation: 1

I face this when was implementing the react-navigation: To solve this issue first we need to install the dependencies correctly for the navigation which we want to use.

I faced this issue when working with stack Navigation:

  1. Install the depaendency >> npm install @react-navigation/stack

  2. npm install react-native-gesture-handler

  3. npm install @react-native-masked-view/masked-view

  4. npx pod-install ios (for mac User)

  5. to very that these are installed properly : open the project in the editor >> go to package.json file >> verify the depencies are there .

  6. Close the application and rebuild it again.

Upvotes: 0

alican akyol
alican akyol

Reputation: 288

Open your MainApplication.java and add top of the code;

import com.th3rdwave.safeareacontext.SafeAreaContextPackage;

Then add the below code in getPackages() function;

packages.add(new SafeAreaContextPackage());

Upvotes: 0

Lahiru Yapa
Lahiru Yapa

Reputation: 1

npm i [email protected] -D -E

Upvotes: 0

I have a solution for android only. That is you just need to follow the steps below In your terminal.

[your project path]\> cd android and Enter.

Then, if you're in PowerShell just type the command below.

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

if you're in cmd type the command below.

[your project path]\android\> gradlew clean

and restart your react native project.

Upvotes: 0

TripleM
TripleM

Reputation: 1252

In the newer version of React Navigation we have to manually install react-native-safe-area and even react-native-screens. I have solved a similar issue by doing sudo npm install react-native-safe-area , sudo npm install react-native-screens. Then clear the app data from my android and reinstalled the app. Open new terminal (Ubuntu 20.04 LTS) then run npm start. Try this one , it might be helpful.

Upvotes: 2

meowww
meowww

Reputation: 153

Are you try: cd ios && pod install && cd .. Then close app, close all terminal and rebuild your app. Hope help you.

Upvotes: 0

Related Questions