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!