Saturday, October 1, 2022
HomeiOS Developmentios - How to pop to rootController onDisappear from SwiftUI view

ios – How to pop to rootController onDisappear from SwiftUI view

[ad_1]

I have a two ViewControllers A and B and a SwiftUI view, navigating from “A” controller to SwiftUIview inside this implemented NavigationLink to navigate -> “B” controller. Trying to pop back to Controller “A” from “B” skipping SwiftUI in between

below solution are not working

.onDisappear tried something like this presentationMode.wrappedValue.dismiss()

On A ViewController

func integrateSwiftUIView() {
        
        let hostingController = UIHostingController(rootView: swiftUIView)

        addChild(hostingController)
        view.addSubview(hostingController.view)

        hostingController.view.translatesAutoresizingMaskIntoConstraints = false
        let constraints = [
            hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
            hostingController.view.leftAnchor.constraint(equalTo: view.leftAnchor),
            view.bottomAnchor.constraint(equalTo: hostingController.view.bottomAnchor),
            view.rightAnchor.constraint(equalTo: hostingController.view.rightAnchor)
        ]

        NSLayoutConstraint.activate(constraints)

        hostingController.didMove(toParent: self)
    }

On integrateSwiftUIView using UIViewControllerRepresentable to reach BViewController

                NavigationLink(isActive: $isPresented) {
                    LaunchBViewController()
                    }) {
                }
  1. Pop back directly to AViewController from BViewController
  2. Dismiss SwiftUIView

[ad_2]

Source link

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments