我有一个现有的应用程序,我正在将它的一部分集成到React-Native中。我是
无法理解如何“退出” native react 并返回 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];

}

我最初的 react 观点是这样的:
render() {
  return (
      <Navigator
          style={styles.container}
...

我在导航器上有一个向右导航按钮,我想“关闭” react View 和基础MainViewController native View 。

我已经尝试像这样从 react View 回调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];

}

对于“退出” react native View 并返回 native View 的方法的任何帮助将不胜感激。

最佳答案

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

其要点是:

  • 在Obj-C中创建一个NotificationManager类,并将其作为React Module公开
  • 在ViewController寄存器中获取通知,该通知在接收时会触发[self dismissViewController ..]
  • 10-08 08:40
    查看更多