SwiftUI: Sizing a popover to fit
On macOS the code below will look like this:
struct PopoverExample: View {
@State private var showingPopupA:Bool = false
var body: some View {
HStack {
Button(action: {
self.showingPopupA.toggle()
}, label: {
Text("Button")
}).popover(isPresented: self.$showingPopupA) {
VStack {
Button(action: {
// Do something
self.showingPopupA = false
}) {
Text("Option A")
}
Button(action: {
// Do something
self.showingPopupA = false
}) {
Text("Option B")
}
}.background(Color.red)
}
}
.frame( maxWidth: .infinity, maxHeight: .infinity)
}
}
Project link
It looks like this has been fixed in iOS 13.4 / Xcode 11.4 Beta. The popover will size to whatever it's contents are now.