Application has not been registered (react-native-navigation v2)

Omar Faroque Anik picture Omar Faroque Anik · Jun 4, 2018 · Viewed 9.5k times · Source

React native navigation v2 issue.

My app starts with index.js and it is registered into AppDelegate as well. Here is the details:

import { AppRegistry } from 'react-native'; const { start } = require('./src/app'); start();

Here app.js:

```

const { Navigation } = require('react-native-navigation');
const { registerScreens } = require('./screens');
const { Platform } = require('react-native');

if (Platform.OS === 'android') {
alert = (title) => {
    Navigation.showOverlay({
        component: {
            name: 'navigation.playground.alert',
            passProps: {
                title
            },
            options: {
                overlay: {
                    interceptTouchOutside: true
                }
            }
        }
    });
};
}

function start() {
registerScreens();
Navigation.events().registerAppLaunchedListener(() => {
    Navigation.setDefaultOptions({
        _animations: {
            startApp: {
                y: {
                    from: 1000,
                    to: 0,
                    duration: 500,
                    interpolation: 'accelerate',
                },
                alpha: {
                    from: 0,
                    to: 1,
                    duration: 500,
                    interpolation: 'accelerate'
                }
            },
            push: {
                topBar: {
                    id: 'TEST',
                    alpha: {
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'accelerate'
                    }
                },
                bottomTabs: {
                    y: {
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate',
                    },
                    alpha: {
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'decelerate'
                    }
                },
                bottomTabs: {
                    y: {
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate',
                    },
                    alpha: {
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'decelerate'
                    }
                },
                content: {
                    y: {
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate',
                    },
                    alpha: {
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'accelerate'
                    }
                }
            },
            pop: {
                topBar: {
                    id: 'TEST',
                    alpha: {
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate'
                    }
                },
                bottomTabs: {
                    y: {
                        from: 0,
                        to: 100,
                        duration: 500,
                        interpolation: 'accelerate',
                    },
                    alpha: {
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate'
                    }
                },
                bottomTabs: {
                    y: {
                        from: 0,
                        to: 100,
                        duration: 500,
                        interpolation: 'decelerate',
                    },
                    alpha: {
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate'
                    }
                },
                content: {
                    y: {
                        from: 0,
                        to: 1000,
                        duration: 500,
                        interpolation: 'decelerate',
                    },
                    alpha: {
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate'
                    }
                }
            }
        }
    });

    Navigation.setRoot({
        root: {
            stack: {
                id: 'TEST',
                children: [
                    {
                        component: {
                            name: 'rp.welcome'
                        }
                    }
                ]
            }
        }
    });
});
}


module.exports = {
  start
};

Screen Registrations:

const { Navigation } = require('react-native-navigation');
const WelcomeScreen = require('./WelcomeScreen');
const Authentication = require('./Authentication').default;
const Tutorial = require('./Tutorial');

function registerScreens() {
Navigation.registerComponent(`rp.welcome`, () => WelcomeScreen);
Navigation.registerComponent(`rp.tutorial`, ()=>Tutorial);
Navigation.registerComponent(`rp.authentication.super`,()=> Authentication);
}

module.exports = {
 registerScreens
 };

Env:

"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-navigation": "^2.0.2314",
"react-native-video": "^2.1.1",
"rn-viewpager": "^1.2.9"
 },

Answer

RedGiant picture RedGiant · Aug 17, 2018

I had a similar issue in V2, and the problem was caused by not removing the rootView settings in the didFinishLaunchingWithOptions methods in AppDelegate.m.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];


  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"XXXXXXXXXX"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  return YES;
}

If you leave them in, It will cause the Application XXXXXXXXXX has not been registered error. The IOS instructions in https://wix.github.io/react-native-navigation/v2/#/docs/Installing should stress that these rootView related lines must be removed.

The correct AppDelegates.m should be like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

  return YES;
}