ios – React-Native:关闭/退出React-Native View返回Native

我有一个现有的应用进程,我正在努力为其中的一部分集成React-Native.我是

无法理解如何“退出”本地反应并返回原生视图.

这是一些代码:

// 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];

}

我最初的反应意见如下:

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

我在导航器上有一个右导航按钮,我想“解除”反应视图和底层MainViewController本机视图.

我已经尝试从反应视图回调MainViewController,但没有用:

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];

}

任何有关“退出”反应本机视图并返回本机视图的方法的帮助将不胜感激.

我发现它的唯一方法是 this

它的要点是:

>在Obj-C中创建一个NotificationManager类并将其公开为React Module

>在ViewController寄存器中获取接收触发时的通知[self dismissViewController ..]

翻译自:https://stackoverflow.com/questions/35298144/react-native-dismiss-exit-react-native-view-back-to-native