SwiftUI: Menu not responding after Sheet is closed

Problem

When dismissing a Sheet any Menu buttons become unresponsive.

Detailed Description

I have a Menu in the toolbar, which becomes unresponsive right after the Sheet is dismissed. The action on the button is highlighted, so it recognizes the tap, but it doesn't do anything. When I tap on it a second time the Menu is working fine again.

The problem doesn't occur when the sheet is dismissed by swiping down.

The behavior is the same in the simulator and on device.

Whenever I click on the Menu I get the following output in the debug area:

2021-10-14 19:30:08.656272+0200 MenuTest[71454:12250609] [UICollectionViewRecursion] cv == 0x12f813000 Disabling recursion trigger logging

However when the button is not responding i get the following output:

2021-10-14 19:32:55.102149+0200 MenuTest[71454:12250609] [UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.

I reduced everything else from my code to narrow down the problem, but I ended up with pretty much the basics now and still have the problem.

Here is the code for the ContentView :

struct ContentView: View {

    @State private var showingSheet = false
    
    var body: some View {
        NavigationView {
            Button(action: {showingSheet = true}) {
                Text("Open Sheet")
            }
            .navigationTitle("MenuBugTest")
            .toolbar {

                ToolbarItem(placement: .primaryAction) {

                    Menu {

                        Button(action: {}) {

                            Label("MenuButton", systemImage: "rectangle.stack.badge.plus")

                        }
                    }
                label: {
                    Text("Open Menu")
                }

                }

            }

        }
        .sheet(isPresented: $showingSheet, content: {

            SheetView()

        })

    }

}

Here the code for the presented sheet:

struct SheetView: View {

    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        NavigationView {
            Text("Sheet")
                .toolbar {
                    ToolbarItem(placement: .primaryAction) {
                        Button(action: {self.presentationMode.wrappedValue.dismiss()}) {
                            Text("Done")
                        }
                    }
                }
        }

    }

}

I also provided a small project in this repository

 Things I tried to solve the problem:

  • putting the @Environment(.presentationMode) variable additionally in ContentView

  • using the new dismiss action available in iOS15

  • using the method of setting the original „showingSheet“ Bool with a Binding to dismiss the sheet

  • putting the menu in various places

  • putting a ternary operator into the menu checking the „showingSheet“  Bool, to force an update

  • switching to a fullScreenCover instead

  • various other things that didn’t help

What am I missing here? Is this a bug? Any workarounds? I am grateful for any help. Thank you!

Having the same or similar issue...Once I tap on the menu item, the correct sheet is displayed. Once I dismiss the sheet, the menu "button" on the toolbar is unresponsive to another tap. The output message is: while no context menu is visible. This won't do anything. Tapping the menu button a second time, opens the menu.

So, it appears that the menu button recognizes that the context menu is still open, even though it isn't. Not sure how to dismiss the context menu when the sheet that the menu option opened is dismissed.

I am hitting this exact wall right now. Before finding this thread I did all the same things you commented - with the same results too :-/

I’m about to ditch Menu for a non-native menu solution because I really like the UX with a sheet being presented from the menu.

What did you end up doing?

Adding

Menu {
...
}
.id(UUID())

Would fix the issue but this isn't at all an ideal solution. 😞

Hi there, sorry for the late response.

Currently I have added a primaryAction to the menu that triggers a confirmationDialog. Not very clean and less than ideal for my use case, but reliable. Sorry I can't give you a better answer. At this point I am just going with this workaround and hope for a fix in the future.

Thanks for your response anyways. Best,

Anyone got solution for this?

Same problem here, definitely a bug. Can we please get an official response on this?

Can we please get an official response on this?

To be clear, DevForums is not an official support channel. Some folks try to help out where they can but, if you want official support, open a DTS tech support incident and speak to one of our SwiftUI experts.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I had the same issue.

  1. The Menu would not respond the first time after the sheet is dismissed, but would respond when I click on it the second time.
  2. The Menu would open the first time only if the sheet was dismissed by dragging down.

Fix that worked for me: Adding @Environment(\.dismiss) private var dismiss to the parent view along with the .id(UUID()) on the Menu (as suggested by @JPHC) made the Menu respond on every click

Many thanks to @devgrammi. I also have not experienced any problems with menus and/or buttons since following their 2-step fix.

SwiftUI: Menu not responding after Sheet is closed
 
 
Q