React-Native:撤消/退出React-Native视图并返回本机视图

React-Native:撤消/退出React-Native视图并返回本机视图

问题描述:

我有一个现有的应用程序,我正在为其中的一部分集成React-Native.我是 无法理解如何退出"本机反应并返回本机视图.

I have an existing app that I am working on integrating React-Native for a portion of it. I am having trouble understanding how to 'exit' react-native and get back to a native view.

以下是一些代码:

// 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 react views are such:

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

我在导航器上有一个向右导航按钮,我想关闭"反应视图和基础的MainViewController本机视图.

I have a right-nav button on the Navigator that I would like to "dismiss" the react view and the underlying MainViewController native view.

我已经尝试过像这样从反应视图回调MainViewController,但无济于事:

I have tried a callback to MainViewController from the react view like so, but without 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, i.e. _rootView removeFromSuperview];

}

在退出"反应本机视图并返回本机视图方面的任何帮助将不胜感激.

Any help with an approach to 'exit' the react-native view and get back into native views would be appreciated.

我发现这项工作的唯一方法是

The only way I've found this works is this

其要旨是:

  1. 在Obj-C中创建NotificationManager类,并将其公开为React Module
  2. 在ViewController寄存器中获取通知,该通知在接收时会触发[self dismissViewController ..]