Popovers
Popovers copied to clipboard
How do I show popover at start?
Trying to show a popover as soon as a view appears.
@State var showingPopover: Bool = false
var body: some View {
Button {
showingPopover.toggle()
} label: {
Image(systemName: "questionmark.circle")
.font(.title)
.foregroundColor(.primary)
}
.popover(present: $showingPopover) {
PopoverView()
}
.onAppear() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
showingPopover = true
}
}
}
Setting showingPopover = true in onAppear without delay (asyncAfter) fails 100%
[Popovers] - No window was found when presenting popover. Please file a bug report (https://github.com/aheze/Popovers/issues).
I can kinda get it to work by adding delay but this isn't super reliable.
Any ideas?
Yeah it takes a bit for the window to first become available. This is to support multiple windows on iPadOS... anyway, the best bet right now is probably just adding a 0.1 second delay.
This happened to me as well. Can confirm that adding a slight delay (I used 0.2s) during onAppear
as suggested works as expected.
I agree with @stbdang that this isn't super reliable and it'd be nice to have a more deterministic way to ensure things work as expected.