Post

Replies

Boosts

Views

Activity

SwiftUI: How to size a popover to content with a Form on iOS 14.5
I am having a problem getting a popover on an iOS app (simulator iOS 14.5) to size correctly to the content if I use a Form in the popover. I have a popover as such: ... .popover(isPresented: $showPersonEditor) { PersonEditor(chosenPerson: $chosenPerson) .environmentObject(document) } ... Within my PersonEditor struct, if I create a Stack in the body as follows, then the popover sizes correctly according to the content: ... VStack(spacing: 0) { Text("Person Editor").font(.headline).padding() Divider() TextField("Name", text: $name, onEditingChanged: { began in if (!began) { document.renamePerson(chosenPerson, to: name) } }).padding() TextField("Add info", text: $infoToAdd, onEditingChanged: { began in if (!began) { chosenPerson = document.addInfo(infoToAdd, toPerson: chosenPerson) infoToAdd = "" } }).padding() Text("Test") Spacer() } However, when I use a Form within the VStack in order to group my fields, then the popover doesn't size correctly anymore! Instead it just shows the popover title and a tiny bit underneath. This is the code with the form: VStack(spacing: 0) { Text("Person Editor").font(.headline).padding() Divider() Form() { Section { TextField("Name", text: $name, onEditingChanged: { began in if (!began) { document.renamePerson(chosenPerson, to: name) } }).padding() TextField("Add info", text: $infoToAdd, onEditingChanged: { began in if (!began) { chosenPerson = document.addInfo(infoToAdd, toPerson: chosenPerson) infoToAdd = "" } }).padding() } Section(header: Text("Test")) { Text("Test") } } Spacer() } This worked with the simulator for iOS 13.4.x but does not work with 14.5. Can anyone help? Thanks, Kristian.
2
0
6.3k
May ’21