2016-02-09 17 views
5

React-Nativeの一部を統合するための既存のアプリケーションがあります。私は で、反応ネイティブを「終了」してネイティブビューに戻る方法を理解することができません。React-Native:React-Nativeを終了/終了する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ネイティブビューう「終了」へのアプローチの任意の助けに

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

} 

反応し、ネイティブビューをネイティブビューに戻ろう:私はしかし、無駄のない、そのような反応観点からMainViewControllerへのコールバックを試してみました

感謝する。

答えて

0

注:これは「TのWORKをdoesnの - 私は動作しないものの例として、ここではこれを残してきた作品のアプローチのための私の他の答えをチェック

お存在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クラスを作成し、トリガーの受信通知を登録するのViewControllerでモジュール
  2. に反応として公開[自己dismissViewControllerを..]
関連する問題