HomeiOS Developmentios - dismiss SwiftUI View and likewise presenting SwiftUI View from...

ios – dismiss SwiftUI View and likewise presenting SwiftUI View from one button in introduced SwiftUI view


I’ve a swiftUI view that’s introduced utilizing a hostingController:

let hostingController = UIHostingController(rootView: FirstView)
 someVC.current(hostingController, animated: true)

The FirstView in flip presents a second SwiftUI view utilizing .sheet(IsPresented with a boolean to find out whether or not it must be displayed as follows:

struct FirstView: View {
    @Atmosphere(.presentationMode) var presentationMode

    @State var showSecondView = false
//change showSecondView to true so it shows as a sheet

 .sheet(isPresented: $showSecondView) {
                SecondView() 
            }
}

In SecondView, I’ve a button that I wish to use to dismiss each the SecondView and the FirstView as properly. It dismisses the SecondView however I can not determine dismiss the FirstView as properly this for the reason that FirstView was introduced in a internet hosting controller not utilizing a boolean.

If the SecondView was say an Alert inside the First View, then I may use the environmental varialbe presentationMode to dismiss, nonetheless, that variable doesn’t appear to be accessible from SecondView.

 struct SecondView: View {
        @Atmosphere(.dismiss) var dismiss
    
    
    Button("OK") {
//THIS DOES NOT WORK BECAUSE presentationMode is out of scope
                presentationMode.wrappedValue.dismiss()
  
                dismiss()//
            }
    }

How can I dismiss not solely the present (or Second) sheet but additionally the presenting (or First view) which was introduced in a hostingController.

Thanks upfront for any ideas.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments