Popover (or sheet) is not working when Menu, Picker, etc is displayed.
struct ContentView: View {
@State private var showPopover = false
var body: some View {
HStack {
Menu {
ForEach(0 ..< 8) { number in
Button {
} label: {
Text("\(number)")
}
}
} label: {
Text("Menu")
}
Button {
showPopover = true
} label: {
Text("Popover")
}
.popover(isPresented: $showPopover) {
Text("hello")
}
}
}
}
If I run the application with the above code and try to show the popover when the menu is open, I will get the error [Presentation] Attempt to present
and will never be able to show the popover again.
I have found a way to delay processing of present as a workaround, but it is not ideal.
For example,
struct ContentView: View {
@State private var showPopover = false
var body: some View {
HStack {
Menu {
ForEach(0 ..< 8) { number in
Button {
} label: {
Text("\(number)")
}
}
} label: {
Text("Menu")
}
Button {
Task {
try await Task.sleep(nanoseconds: 300_000_000)
showPopover = true
}
} label: {
Text("Popover")
}
.popover(isPresented: $showPopover) {
Text("hello")
}
}
}
}