Push a native ios view to the stack

Hi all

I am looking to add a native view to my Capacitor 4 application that can be opened by a Capacitor plugin. I currently have this working using the Capacitor viewController.bridge.present method, but it is presenting as a modal on top of the main CAPBridgeViewController.

Instead, I would like to have a native navigation stack and push a ViewController onto this stack using something like self.bridge?.viewController?.navigationController?.pushViewController(myNewVC). Is there a way to do this with Capacitor? Would I need to add a navigation stack natively somehow and subclass CAPBridgeViewController?

Any help here would be appreciated. If it is not possible this way, would this be a good use case for Portals? We have 95% of navigation in a web application, but there is one important screen that is fully native and it doesn’t seem it should be presented modally but as a new entry in a stack.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) → Bool {
let navigationController = NavigationViewController.init(rootViewController:CAPBridgeViewController())
window?.rootViewController = navigationController
return true
}

1 Like

The above answer is correct except NavigationViewController should be UINavigationController.

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let navigationController = UINavigationController.init(rootViewController:CAPBridgeViewController())
        window?.rootViewController = navigationController     
        return true
    }

And somewhere in your plugin code just do:

self.bridge?.viewController?.pushViewController(vc, animated: true)