React-Native iOS - How can I navigate to a non-React-Native view (native iOS view controller) from a React-Native view with a button press?

前端 未结 3 1846
清歌不尽
清歌不尽 2020-12-03 05:37

The RN doco and other examples show how to launch a React-Native view from a native iOS view controller, but not the other way around. Can someone explain how I can do this

3条回答
  •  囚心锁ツ
    2020-12-03 06:34

    There is little improvement on this solution.With present solution there is no way to come back to React-Native from iOS. 
    
    If you want to come back again from iOS to React-Native.Do the below
    
     // AppDelegate.h
    
        - (void) goToNativeView {
         UIViewController *vc =  [InitialViewController new];// This is your native iOS VC
         UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    
          dispatch_async(dispatch_get_main_queue(), ^{
           // Never do the below, it will be difficult to come back to react-native
    
           // self.window.rootViewController = navigationController;
    
            // Do this instead
            [self.window.rootViewController presentViewController:navigationController animated:true completion:NULL];
          });
        }
    
    //InitialViewController.m
    
        **-Create a button for go back to React-native and on button action dismiss this view controller like below.**
    
        // Dismiss the VC so controll go back from iOS to react-native
            [self dismissViewControllerAnimated:TRUE completion:nil];
    

提交回复
热议问题