2016-02-09 27 views
5

Tôi có một ứng dụng hiện có mà tôi đang làm việc để tích hợp React-Native cho một phần của nó. Tôi là không hiểu được cách 'thoát' phản ứng gốc và quay lại chế độ xem gốc.React-Native: Loại bỏ/Thoát chế độ xem gốc tự nhiên về Native

Dưới đây là một số mã:

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

} 

tôi ban đầu phản ứng quan điểm là như vậy:

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

Tôi có một nút chuột phải nav trên Navigator mà tôi muốn "giải tán" những phản ứng xem và chế độ xem gốc cơ bản của MainViewController.

Tôi đã thử một callback để MainViewController từ quan điểm phản ứng như vậy, nhưng không có avail:

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

} 

Bất kỳ sự giúp đỡ với một cách tiếp cận để 'thoát' quan điểm phản ứng bản địa và trở lại vào quan điểm bản địa sẽ được đánh giá cao.

Trả lời

0

LƯU Ý: NÀY doesn "CÔNG VIỆC T - Tôi đã để lại ở đây như một ví dụ về những gì không hoạt động Kiểm tra câu trả lời khác của tôi cho một cách tiếp cận mà làm việc

Nếu bạn có mặt MainViewController cách này, popViewController:.. nên làm việc

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

Xin lỗi, đó dường như không làm việc . – dnstevenson

+0

Có thể Xác nhận điều này không hoạt động, xin lỗi – Tejas

1

cách duy nhất tôi đã tìm thấy các công trình này được this

các ý chính của nó là:

  1. Tạo một lớp NotificationManager trong obj-C và phơi bày nó như Phản ứng Mô-đun
  2. Trong ViewController đăng ký một thông báo mà khi nhận trigger [tự dismissViewController ..]
Các vấn đề liên quan