{"action":"opened","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/22676","repository_url":"https://api.github.com/repos/facebook/react-native","labels_url":"https://api.github.com/repos/facebook/react-native/issues/22676/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/22676/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/22676/events","html_url":"https://github.com/facebook/react-native/issues/22676","id":391563711,"node_id":"MDU6SXNzdWUzOTE1NjM3MTE=","number":22676,"title":"@oceantang I also wanted to something similar, but ended up just replacing the `rootViewController`","user":{"login":"kartikqss","id":29063730,"node_id":"MDQ6VXNlcjI5MDYzNzMw","avatar_url":"https://avatars3.githubusercontent.com/u/29063730?v=4","gravatar_id":"","url":"https://api.github.com/users/kartikqss","html_url":"https://github.com/kartikqss","followers_url":"https://api.github.com/users/kartikqss/followers","following_url":"https://api.github.com/users/kartikqss/following{/other_user}","gists_url":"https://api.github.com/users/kartikqss/gists{/gist_id}","starred_url":"https://api.github.com/users/kartikqss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kartikqss/subscriptions","organizations_url":"https://api.github.com/users/kartikqss/orgs","repos_url":"https://api.github.com/users/kartikqss/repos","events_url":"https://api.github.com/users/kartikqss/events{/privacy}","received_events_url":"https://api.github.com/users/kartikqss/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-17T05:32:52Z","updated_at":"2018-12-17T05:32:52Z","closed_at":null,"author_association":"NONE","body":"``` objc\r\n#import \"AppDelegate.h\"\r\n#import \"RCTRootView.h\"\r\n\r\n@interface AppDelegate()\r\n\r\n// keep a reference to the React Native VC\r\n@property (nonatomic, strong) UIViewController *reactNativeViewController;\r\n\r\n@end\r\n\r\n\r\n@implementation AppDelegate\r\n\r\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\r\n{\r\n  NSURL *jsCodeLocation;\r\n\r\n  jsCodeLocation = [NSURL URLWithString:@\"http://localhost:8081/index.ios.bundle\"];\r\n\r\n  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation\r\n                                                      moduleName:@\"CrowdTest\"\r\n                                                   launchOptions:launchOptions];\r\n\r\n  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];\r\n\r\n  // keep a reference to the React Native VC\r\n  self.reactNativeViewController = [[UIViewController alloc] init];\r\n  self.reactNativeViewController.view = rootView;\r\n\r\n  self.window.rootViewController = self.reactNativeViewController;\r\n  [self.window makeKeyAndVisible];\r\n\r\n  return YES;\r\n}\r\n\r\n\r\n- (void)goToReactNative {\r\n\r\n  [self.window.rootViewController dismissViewControllerAnimated:TRUE completion:nil];\r\n\r\n}\r\n\r\n- (void)goNativeStoryboard {\r\n\r\n  UIViewController *vc = [UIStoryboard storyboardWithName:@\"NativeStoryboard\" bundle:nil].instantiateInitialViewController;\r\n\r\n  [self.window.rootViewController presentViewController:vc animated:true completion:nil];\r\n\r\n}\r\n@end\r\n```\r\n\r\ncall the bridge method `SwiftApp.goToNative()` from ReactNative js\r\n\r\n``` swift\r\n@objc(SwiftApp)\r\nclass SwiftApp: NSObject {\r\n  @objc func goToNative() -> Void {\r\n    if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {\r\n      appDelegate.goNativeStoryboard()\r\n    }\r\n  }\r\n```\r\n\r\nand to go back to ReactNative\r\n\r\n``` swift\r\nimport UIKit\r\n\r\nclass NativeViewController: UIViewController {\r\n\r\n    @IBAction func onClick(sender: AnyObject) {\r\n      if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {\r\n        appDelegate.goToReactNative()\r\n      }\r\n    }\r\n\r\n}\r\n```\r\n\r\nthis is somewhat hacky, but allows you to work directly with native iOS components which aren't yet fully supported.\r\n\r\nhope it helps\r\n\r\n_Originally posted by @yelled3 in https://github.com/facebook/react-native/issues/1148#issuecomment-102008892_"}}
{"actor":{"display_login":"kartikqss"}}