Which is already presenting occurs when another View is presented while the Menu is displayed in SwiftUI.

Certainly, here's an explanation and the minimal code to reproduce the issue in English:

In SwiftUI, attempting to present a sheet or any other presentation view while a Menu view is open causes a conflict. This is because SwiftUI does not allow multiple presentation views to be open at the same time. Here's the simplest code to reproduce the issue:

import SwiftUI

struct ContentView: View {
    @State var showSheet = false

    var body: some View {
        VStack {
            Menu {
                Button("Option 1") { }
                Button("Option 2") { }
            } label: {
                Text("Open Menu")
            }

            Button(action: {
                showSheet = true
            }) {
                Text("Open Sheet")
            }
            .sheet(isPresented: $showSheet) {
                Text("Hello, Sheet!")
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

To handle this issue appropriately, a few possible solutions could be:

Provide a Binding argument to the Menu, allowing for better control over its state. Disable the button when the Menu is visible. This will prevent another presentation view from attempting to open while the Menu is open. Ensure that if a button is pressed, any already presented Menu is properly dismissed before trying to present another view. The most suitable solution would likely be to disable any background buttons while the Menu is visible.

I suspect this was addressed in iOS 17, as this appears to no longer be an issue when using this sample code.

I'm developing against iOS 16 and still need to work around this issue.

Which is already presenting occurs when another View is presented while the Menu is displayed in SwiftUI.
 
 
Q