Skip to content

Instantly share code, notes, and snippets.

@jdnichollsc
Last active March 22, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdnichollsc/f59f13e86ee0ac6480ad1506c6402984 to your computer and use it in GitHub Desktop.
Save jdnichollsc/f59f13e86ee0ac6480ad1506c6402984 to your computer and use it in GitHub Desktop.
React Native - Tips
  • Get root navigation controller
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *rootController = [[delegate window] rootViewController];
UINavigationController *rootNavigationController = (UINavigationController *)rootController;
  • Present view controller
UIViewController *ctrl = [UIViewController new];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:ctrl];
UIViewController *presentingViewController = RCTPresentedViewController();
[presentingViewController presentViewController:navigationController animated:FALSE completion:nil];
  • Get the top controller
- (UIViewController*) topMostController {
  UIViewController *topController = [UIApplication sharedApplication].delegate.window.rootViewController;
  
  while (topController.presentedViewController) {
    topController = topController.presentedViewController;
  }
  
  return topController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment