'Can I instantiate a ViewController, and await completion of tasks a few ViewControllers down the line before continuing?

I'm working on integrating an existing iOS application into React-Native, the friend I'm helping is insistent on using their existing custom UIViewControllers with as little modification as possible.

The goal is:

react-native -> (objc vc1)find bluetooth camera -> (objc vc2)send wifi information to camera -> (objc vc3)connect to camera -> (objc vc3)return data -> return to react-native root controller

I've got the hardware successfully connecting.

So, in my bridge, I'm exporting this method which when called in js opens the native view controller:

RCT_EXPORT_METHOD(changeToBluetoothView)
{
  dispatch_async(dispatch_get_main_queue(), ^ {
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    AddDeviceBLEInitViewController *vc = (AddDeviceBLEInitViewController *)[storyboard instantiateViewControllerWithIdentifier:@"AddDeviceBLEInitViewController"];
    appDelegate.window.rootViewController = vc;
  });
}

In which the next view controllers in instantiated etc...

What I need to do is wait for the user to finish connecting the camera, return the data, and continue the execution of my react project, but I can't for the life of me think of an elegant way to do it. Can I use RCT_REMAP_METHOD and promises to await completion of vc3?

Is there a way to nest callbacks that are completed upon success of each stage that finally returns to the method call, which in turn continues the execution of the react code?



Solution 1:[1]

I wound up using RCTEventEmitter to solve this problem.

I made a class method that emitted an event, which I then called from my final view controller.

This thread ound up being very helpful, and other than some minor changes it was correct almost verbatim:

Using RCTEventEmiitter

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rej Fredericks