iosobjective-cswiftreactjsreact-native

Can't dismiss presented view controller through React Native


I am doing a hybrid implementation of react-native. I am presenting the React View Controller like so:

self.vc = [[ContactForm alloc] init];
self.vc.modalPresentationStyle = UIModalPresentationFullScreen;
UIViewController *root = [[[UIApplication sharedApplication] delegate] window].rootViewController;
[root presentViewController:self.vc animated:YES completion:nil];

On an action on the react-native page, I need to dismiss this view controller that I presented, through an exported method. I try to do it like so:

@objc(dismissContactForm)
func dismissContactForm() {
    DispatchQueue.main.async {
        self.dismiss(animated: true, completion: nil)
    }
}

It doesn't dismiss, and the view controller stays put. I added the DispatchQueue because when the control comes back to the native app, it comes through a background thread.

How can I solve this?


Solution

  • Found the problem. Using React Native's NativeModules, a new instance of the class is created every time it's called. For now, I have used the window's root view controller to present and dismiss the view controller to get the instance of the presented controller but the callback blocks RCTResponseSenderBlock could also be used.