React-Native: Disable / Exit

I have an existing application in which I am working on integrating React-Native for its part. I am having trouble understanding how to "get out" react-native and get back to my own look.

Here is the code:

// Main objective-c code that bootstraps the react-native view. This view is loaded as a modal view. MainViewController.m: - (void)viewDidLoad { [super viewDidLoad]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"IndexApp" initialProperties:props launchOptions:nil]; rootView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-49); [self.view addSubview:rootView]; } 

My initial opinion is as follows:

 render() { return ( <Navigator style={styles.container} ... 

I have a right navigator button in the Navigator that I would like to β€œreject” in the reaction view and in the main view of MainViewController.

I tried the MainViewController callback from a reactive view like this, but to no avail:

 RCT_EXPORT_METHOD(dismiss:(NSString *)name location:(NSString *)location) { NSLog(@"dismiss..."); // these don't do anything //[self dismissViewControllerAnimated:YES completion:nil]; //[self.navigationController popViewControllerAnimated:YES]; // anything with _rootView doesn't do anything, ie _rootView removeFromSuperview]; } 

Any help with approaching the "exit" due to reverse lookup and returning to your own views will be appreciated.

+6
source share
3 answers

The only way I found this is this

Its essence is as follows:

  • Create a NotificationManager class in Obj-C and publish it as a React Module
  • In the ViewController register for a notification that when triggers are received [self rejectViewController ..]
+1
source

NOTE: THIS IS TEN T WORK - I left this here as an example of what doesn't work. Check out my other answer for an approach that works.

If you represent MainViewController this way, popViewController: should work

 NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; RCTRootView *reactView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"SimpleApp" initialProperties:nil launchOptions:nil]; MainViewController *rootViewController = [MainViewController new]; rootViewController.view = reactView; [[self navigationController] pushViewController:rootViewController animated:YES]; 
0
source

You need to run pop or remove in the main thread:

 RCT_EXPORT_METHOD(dismiss:(NSString *)name location:(NSString *)location) { NSLog(@"dismiss..."); dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; // use pop instead if this view controller was pushed onto a navigation controller //[self.navigationController popViewControllerAnimated:YES]; } } 
0
source

All Articles