Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

swift - How to push onto an existing UINavigationController stack from SwiftUI?

We're pushing to a SwiftUI view embedded in a UIHostingViewController in UIKit land like this:

First making the UIViewController:

    func hostingController() -> UIViewController {
    let swiftUIView = swiftUIView(viewModel: viewModel(data: [Data, Data, Data]))
    return UIHostingController(rootView: swiftUIView)
}

Then pushing it onto the UINavigationView stack:

[self.navigationController pushViewController:hostingViewController animated:YES];

This gets us to SwiftUI's environment. But, if our SwiftUI environment has it's own navigation stack with NavigationView and NavigationLink, the original navigationBar's back button can only navigate back to the original presenting UIViewController.

Is there a way to push a SwiftUI view embedded in a NavigationView onto an existing UINavigationController stack?

The only thought we've had so far is creating a new UIHostingViewController for each new SwiftUI screen, and pushing that onto the stack via some kind of delegate method.

What we're looking for is something like this:

UINavigationStack: [UIViewController -> UIViewController -> SwiftUIView -> SwiftUIView]

Where the back < arrow in the navigationBar will behave as expected.

Please let us know if we can clarify further!

question from:https://stackoverflow.com/questions/65892021/how-to-push-onto-an-existing-uinavigationcontroller-stack-from-swiftui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...