Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
 },
like image 939
Omar Faroque Anik Avatar asked Jun 04 '18 15:06

Omar Faroque Anik


3 Answers

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;
}
like image 196
RedGiant Avatar answered Oct 25 '22 17:10

RedGiant


I had the same issue but only on Android. It turned out I had missed a step in the configuration process.

In MainActivity.java it should extend com.reactnativenavigation.NavigationActivity instead of ReactActivity.

https://wix.github.io/react-native-navigation/v2/#/docs/Installing.

like image 25
stephenheron Avatar answered Oct 25 '22 18:10

stephenheron


I have solved this by putting the string name of the component like this:

instead of: component: YourComponent

it should be:

component: {
   name: 'YourComponent'
}

complete code below:

Navigation.events().registerAppLaunchedListener(() => {
    Navigation.setRoot({
        root: {
            stack: {
                children: [
                    {
                        component: {                            
                            name: 'YourComponent'
                        }
                    }
                ]
            }
        }
    })
});

also, if you push or setStackRoot, you should always use component name: e.g.

component: {
name: 'YourComponent'
}
like image 32
GinealSoftwareDev Avatar answered Oct 25 '22 17:10

GinealSoftwareDev