Navigate from one embedded UIViewController in swiftUI to another embedded UIViewcontroller in swift UI

220 Views Asked by At

I have a UIViewController which is embedded in swiftUI View

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
    ContentView(overlayShow: OverlayShow())
    }
}

struct OnboardingWrapper: UIViewControllerRepresentable {
    var overlayShow: OverlayShow
    func makeUIViewController(context: Context) -> ReturnSomthing {
        let controller = ReturnSomthing(shareConfig: onboardingConfig)
        controller.showOverlay = overlayShow
        return controller
    }

   func updateUIViewController(_ uiViewController: ReturnSomthing, context: Context) {
    
    }

    public typealias UIViewControllerType = ReturnSomthing
}

I want to be able to Navigate directly from SwiftUI to another SwiftUI view with embedded UIViewController SO, I did on a view of SwiftUI

struct ContentView: View {
    @ObservedObject var overlayShow: OverlayShow = OverlayShow()
    var body: some View {

        NavigationView {
            NavigationLink(destination: OverlayView(overlay:     LoadingUnknownOverlayViewContainer(description: "it is spinning :0", designModel:     LoadingOverlayDesignModel(type: .unknown))), isActive: $overlayShow.isShowingOverlay) {
                OnboardingWrapper(overlayShow: overlayShow) 
            }
        }
    }
}

the condition for navigation to be active is the overlayShow.isShowingOverlay is true. this variable is controlled in UIViewController with an ObservableObject.

the problem is that no matter the value of overlayShow.isShowingOverlay wherever I tap the first UIViewController which is OnboardingWrapper the navigation is activated and goes to the next page.

To be more clear I post a screen recording. enter image description here Please how can I solve this problem.

1

There are 1 best solutions below

0
On

It sounds like you are seeing OnboardingWrapper and when you click on it, you are seeing OverlayView. Perhaps this would help:

    var body: some View {
        NavigationView {
            OnboardingWrapper(overlayShow: overlayShow)
            NavigationLink(destination: OverlayView(
                overlay:LoadingUnknownOverlayViewContainer(
                    description: "it is spinning :0",
                    designModel: LoadingOverlayDesignModel(type: .unknown))),
                    isActive: $overlayShow.isShowingOverlay) {
                EmptyView() 
            }
        }
    }

OnboardingWrapper will appear, then when overlayShow.isShowingOverlay is true, the OverlayView should be presented.