Sheets no longer open when button is tapped while popover is visible

I have an extremely simple SwiftUI View with two buttons. One displays a sheet, the other one a popover.

struct ContentView: View {

    @State private var showPopover = false
    @State private var showSheet = false

    var body: some View {
        VStack {
            Button("Popover") {
                showPopover = true
            }
            .popover(isPresented: $showPopover, content: {
                Text("Popover content")
            })

            Spacer()

            Button("Sheet") {
                showSheet = true
            }
        }
        .padding()
        .sheet(isPresented: $showSheet) {
            Text("Lorem Ipsum")
        }
    }
}

On iPadOS, when the Popover is visible and the "Sheet" Button (that looks disabled but is not) is pressed, nothing happens and I get the following log:

Attempt to present <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x14508c600> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x14501fe00> (from <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x14501fe00>) which is already presenting <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x140023e00>.

What's even worse is, the "Sheet" Button is now in a broken state and no longer works at all. Is there a way to fix this or am I right in assuming this is a bug?

It is a bug, but it's a bug in your code.

Right before showPopover = true you need to have showSheet = false.

And right before showSheet = true you need showPopover = false.

These two additions will revert the status of the other item so they aren't shown anymore.

You received that "Attempt to present" error because you already had something presented, and were trying to present a second view over the top, which you can't do.

I am not sure if I agree with that, since the Popover is being closed automatically, so I would imagine its value being set to false automatically.

Moreover, in more complex circumstances, the popover and the sheet modifier could be applied to totally different views which do not really know each other.

Hi @nspinner ,

Can you give me more information?

  • are you using a simulator or real device?
  • what iOS version is the sim/device on?
  • what version of Xcode are you on?

Of course, thank you!

  • I am using a simulator
  • I tested with iPadOS 16.2, 17.2 and 17.4
  • I am on Xcode 15.3

I have to clarify, that the issue seems not to be happening with iPadOS 17.4, therefore the problem seemingly was fixed between iPadOS 17.2 and 17.4.

Sheets no longer open when button is tapped while popover is visible
 
 
Q