5

The view is being condensed instead of moved up when the keyboard is presented. It works as expected in portrait mode, the issue only presents in landscape mode. Photos attached for clarification. I have tried .edgesIgnoreSafeArea(), along with the solutions presented on this thread.

VStack {
                
                Text("\(titleText)")
                    .font(.system(size: 30))
                    .bold()
                
                VStack {
                    Text("Item Title")
                    TextField("Item Title", text: $title)
                        .formStyle()
                    
                }
                
                VStack {
                    Text("Item Description")
                    TextField("Item Description", text: $itemDescription)
                    //TextEditor(text: $itemDescription)
                        .formStyle()
                }
                
                VStack {
                    Text("Unit Type")
                    TextField("Each, Total, Hours, LF, etc...", text: $unitType)
                        .formStyle()
                }
                
                VStack {
                    Text("Unit Cost")
                    TextField("Cost per unit", text: $unitCost, onEditingChanged: { (isChanged) in
                        guard !unitCost.isEmpty else { return }
                        //Ensuring entered text can be converted to required double
                        if let _ = Double(unitCost) {
                            isUnitCostValid = true
                        } else {
                            isUnitCostValid = false
                            unitCost = ""
                            alertTitle = .unitCostError
                            alertMessage = "Not a valid Unit Cost. Please enter only numbers."
                            showingAlert = true
                        }
                    })
                    .keyboardType(.numberPad)
                    .formStyle()
                }
                
                Spacer()
                
                Button("\(saveText)") {
                    //code to print to console coredata path for device
                    // print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask))
                    addNewItem()
                }
                .font(.system(size: 30))
                .frame(maxWidth: 400, maxHeight: 100)
                .foregroundColor(.white)
                .background(Color.blue)
                .clipShape(Capsule())
                .disabled(isDisabled)
                .opacity(isDisabled ? 0.7 : 1)
                .alert(isPresented: $showingAlert) {
                    Alert(title: Text(alertTitle.rawValue), message: Text(alertMessage), dismissButton: .default(Text("OK"), action: {
                        if case .saved = alertTitle {
                            settingsPopper.popToSettings()
                            //use presentationMode... if not using our custom popper
                            //presentationMode.wrappedValue.dismiss()
                        }
                    }))
                }
            }

Any ideas?

Before

After

jtbandes
  • 115,675
  • 35
  • 233
  • 266
Jordaleste
  • 51
  • 2
  • Sadly no, I had also tried that before posting. – Jordaleste Oct 03 '20 at 16:45
  • 3
    Ended up solving with a simple solution, embedded the top level VStack in a ScrollView. That took care of it. – Jordaleste Oct 03 '20 at 22:12
  • genius! That really does the trick and is pretty convenient for the user as well! Thanks for sharing – emmics Nov 04 '20 at 08:27
  • 1
    Jordaleste, that solved a keyboard-avoidance problem I had that only appeared on iPads. Would not have found that myself. Keyboard-avoidance has been an Achilles heel long before SwiftUI,,, – Andrew Duncan Jan 23 '21 at 01:36

0 Answers0