I am new to swift (developer from long ago) and have not been able to resolve an issue with IOS - I am building a text entry box with save / cancel buttons at bottom and a texteditor above all within a fixed size frame. It's all OK on macOS but when I try iOS the space taken by the form weirdly expands (beyond the size of the text editor) and end up pushing the save /cancel buttons below outside view. An extract of the code is here. I have tried all sorts of things like setting frame sizes, line limits, spacers, scrolling disable, but I can't stop the behaviour. Any ideas. Apologies if this is well known or my issue due to inexperience I just can't resolve it.
private func editSource(in geometry: GeometryProxy) -> some View {
NavigationStack{ Form { Section(header: Text("Source Name")) { TextEditor(text: $newSourceName) .font(.title3) .padding(5) .background( RoundedRectangle(cornerRadius: 10) .fill(.background) ) .textFieldStyle(PlainTextFieldStyle()) .frame(height: 50) .foregroundColor(.primary) .focused($isSourceFocused) } }
HStack {
Button("Save") {
events[eventIndex].source = newSourceName
isEditingSource = false
isSourceFocused = false
disableEdit = false
}
Spacer()
Button("Cancel", role: .cancel) {
isSourceFocused = false
isEditingSource = false
disableEdit = false
}
}
.padding()
.layoutPriority(1)
}
#if os(macOS) .scrollDisabled(true) .padding() .frame(height: 180) .frame(width: 240) .background(.gray) #else .frame(width: 240) .frame(height: 240)
#endif .cornerRadius(10) .clipShape(RoundedRectangle(cornerRadius: 10)) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(Color.blue, lineWidth: 1) ) .position(sourceLocation) .offset(x: 0, y: 100) .zIndex(1) .onAppear() { isSourceFocused = true newSourceName = events[eventIndex].source } }