Invariant Violation: requireNativeComponent: "RNCSafeAreaProvider" code example

Example: Invariant Violation: requireNativeComponent: "RNCSafeAreaProvider"

Follow These Steps:
I also got that error when setting up react navigations but the below code worked for me.
Paste this code in the files shown below:

1.) android/settings.gradle
	include ':react-native-safe-area-context'
	project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')

2.) android/app/build.gradle
	dependencies {
    	implementation project(':react-native-safe-area-context')
    	...
	}

3.) android/app/src/main/java/com/[APP_NAME]/MainApplication.java
	import com.th3rdwave.safeareacontext.SafeAreaContextPackage;

4.) android/app/src/main/java/com/[APP_NAME]/MainApplication.java (Add this code where the getPackages function exists)
	@Override
	protected List<ReactPackage> getPackages() {
    	return Arrays.asList(
        	...
        	new MainReactPackage(),
        	new SafeAreaContextPackage()
    	);
	}
OR if already a package is returned then this code

    @Override
    protected List<ReactPackage> getPackages() {
        List<ReactPackage> packages = new PackageList(this).getPackages();
        packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
        packages.add(new SafeAreaContextPackage());
        return packages;
    }
      
You can also get this for IOS here :- https://github.com/th3rdwave/react-native-safe-area-context#linking-in-react-native--060-1
I was getting in android so I provided the android code.
      
by sobhan_bera

Tags:

Html Example