2016-02-09 55 views
5

我有一個現有的應用程序,我正在爲它的一部分集成React-Native。我 無法理解如何「退出」反應 - 原生和回到本地視圖。React-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]; 

} 

用一種方法來「退出」的反應,機視任何幫助,並重新進入本地意見將不勝感激。

回答

0

注:這並未「T工作 - 我已經離開這個這裏的什麼行不通的例子檢查我的其他答案,工程的方法

如果您目前MainViewController這種方式,popViewController:。應該工作

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

對不起,但這似乎沒有工作。 – dnstevenson

+0

可以確認這不起作用,對不起 – Tejas

1

的唯一途徑,我發現這個工作原理是this

它的要點是:

  1. 在的OBJ-C創建NotificationManager類並將其公開爲陣營模塊
  2. 在ViewController中註冊,當接收到的觸發器的通知[自dismissViewController ..]