TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SwiftUI, iOS 14, Keyboard Avoidance in Form{ TextEditor() }

Forums > SwiftUI

@bci  

I am having a problem on a simple Form{}. Automatic Keyboard Avoidance is not working. Below is a small form with a TextEditor(). When run, the keyboard sits on top the input field, requiring the user to scroll the view so thay can enter a location. Remove the Form{} and Automatic Keyboard Avoidance works. Am I missing something I need to do in a Form{} to get this behavior?

import SwiftUI
struct ContentView: View {
    @State private var stopLocation: String = ""
    var body: some View {
        Form {
            let desc = "\n\n\n\n\n\n\n\n\n\n\n\nEnter Location"
            Text(desc)
            VStack {
                TextEditor(text: $stopLocation)
            }
        }
    }
}

Thank you.

4      

Hello! Can you please share any update on this? It's really a pain to adopt the whole keyboard avoidance mechanism for just one element like TextEditor().

Would really appreciate!

3      

Having same problem... anyone?

UPDATE I think I found a solution. https://www.vadimbulavin.com/how-to-move-swiftui-view-when-keyboard-covers-text-field/

4      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.