If you’ve set up a brand new React Native project, installed React Navigation, written a bit of code and you’re getting this error, it’s because you didn’t go back and read the documentation and you’ve forgotten that you need to edit the MainActivity.java file to make it work!

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

This error is located at:
    in RNSScreenStackHeaderConfig (at HeaderConfig.tsx:128)
    in HeaderConfig (at NativeStackView.native.tsx:223)
    in MaybeFreeze (at src/index.native.tsx:229)
    in RNSScreen (at createAnimatedComponent.js:242)
    in AnimatedComponent (at createAnimatedComponent.js:295)
    in AnimatedComponentWrapper (at src/index.native.tsx:208)
    in Screen (at NativeStackView.native.tsx:176)
    in SceneView (at NativeStackView.native.tsx:278)
    in RNSScreenStack (at src/index.native.tsx:160)
    in ScreenStack (at NativeStackView.native.tsx:269)
    in NativeStackViewInner (at NativeStackView.native.tsx:323)
    in RNCSafeAreaProvider (at SafeAreaContext.tsx:76)
    in SafeAreaProvider (at SafeAreaProviderCompat.tsx:46)
    in SafeAreaProviderCompat (at NativeStackView.native.tsx:322)
    in NativeStackView (at createNativeStackNavigator.tsx:67)
    in NativeStackNavigator (at App.js:36)
    in EnsureSingleNavigator (at BaseNavigationContainer.tsx:430)
    in BaseNavigationContainer (at NavigationContainer.tsx:132)
    in ThemeProvider (at NavigationContainer.tsx:131)
    in NavigationContainerInner (at App.js:35)
    in App (at renderApplication.js:50)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:92)
    in RCTView (at View.js:32)
    in View (at AppContainer.js:119)
    in AppContainer (at renderApplication.js:43)
    in eartraining(RootComponent) (at renderApplication.js:60)

All the info is here (go back and check it!), but basically you just add this to your MainActivity.java file:

/* in your imports */
import android.os.Bundle;

/* in the body of the file */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(null);
}

Then restart the server and you should be good to go.

Adding Navigation to React Native – Gettin’ Errors?
Tagged on:         

Leave a Reply

Your email address will not be published.