NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

SOLVED: Using .sheet and .fullScreenCover together?

Forums > SwiftUI

Hi

Can anyone confirm that it is not possible to use both the .sheet and .fullScreenCover modifiers together? I have a requirement to use .sheet for some actions (e.g. create a new "Widget"), but then .fullScreenCover for other actions (e.g. view a "Widget").

This is the code I am using:

            .fullScreenCover(isPresented: $showCover) {
                WidgetScreen()
            }
            .sheet(isPresented: $showSheet) {
                WidgetForm()
            }

I have tried swopping the order of the modifiers, but find that only the last modifier of these two is actually applied (e.g. in this case, only the .sheet is "active").

Any help would be appreciated.

Thanks G

1      

I would assume that just like how you can't use two sheet modifiers, you can't use a sheet and a fullScreenCover together either. You would need to attach them to different places in your View for them to work.

   

I tried placing mentioned 2 modifier (sheet & fullScreenCover) into different part of View but could not managed to get it work, is there something that I am missing, any update on this issue?

   

Add them to two different views on the same level.

1      

@twodayslate That was the piece of the puzzle I was missing, could never get it to work.

Added an example for others.

    var body : some View {
        Group {
            ZStack {

                // Allow Sheet and FullScreenCover to work together
                EmptyView()
                    .sheet(isPresented: self.matches(mode: .present), onDismiss: {
                        self.navigator.pop()
                    }) {
                        presentView()
                    }

                switchView()
                    .fullScreenCover(isPresented: self.matches(mode: .fullscreen), onDismiss: {
                        self.navigator.pop()
                    }) {
                        fullScreenView()
                    }
            }
        }
    }

   

Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.