Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI: How to display a full screen view from a sheet

Currently, I have a Navigation Link within a sheet. This creates a new page inside that sheet instead of taking up the full screen. Is there a way to dismiss the sheet and then present the view on the original screen?

Original view with a button pulling up a sheet:

Button {
    userTappedItem = item
} label: {
    ...
}
.sheet(item: $userTappedItem) {
} content: { item in
    NewView(item: item)
}

NavigationLink within NewView:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NavigationLink {
    ViewIWantAsFullScreen()
} label: {
    ...
}

>Solution :

Yes, this is doable. The most important bit is the delay between dismissing the sheet and presenting the full screen cover — without this delay, the full screen cover View just replaces the sheet’s content.

struct ContentView  : View {
    @State private var sheetDisplayed = false
    @State private var fullScreenDisplayed = false
    
    var body: some View {
        VStack {
            Button("Show Sheet") {
                sheetDisplayed.toggle()
            }.sheet(isPresented: $sheetDisplayed) {
                SheetView(closeAndDisplayFullScreen: {
                    sheetDisplayed = false
                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                        fullScreenDisplayed = true
                    }
                    
                })
            }
        }.fullScreenCover(isPresented: $fullScreenDisplayed) {
            FullScreenView()
        }
    }
}

struct SheetView : View {
    var closeAndDisplayFullScreen : () -> Void
    
    var body: some View {
        Button("Show full screen after dismiss") {
            closeAndDisplayFullScreen()
        }
    }
}

struct FullScreenView : View {
    var body: some View {
        Text("Full screen")
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading