UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

4      

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.

3      

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?

3      

Add them to two different views on the same level.

4      

@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()
                    }
            }
        }
    }

3      

Fantastic. I was fighting with this crap for 2 days. Thanks

3      

For people coming form the future, in iOS 14.0 (tested in simulator) you need to write as mentioned in the answer above and separate the .fullScreenCover and .sheet modifiers. In iOS 14.5 (or possibily earlier) and iOS 15 you no longer need to write this way. You can put the .fullScreenCover and .sheet code together.

I'm using SwiftUI in my relative small app and already I have encrountered so many weirdness that seems to be bugs. Be very careful if you want to support iOS 14 or even 13 and make sure you test everything on these versions.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.