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