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

iOS 16 TextField, axis parameter, and keyboard avoidance

Forums > SwiftUI

I've not seen the issue I'm having discussed here or anywhere else since iOS 16 dropped. I've added the axis: .vertical parameter to a TextField view to make it expand vertically, eliminating the need for a ZStack hack that accomplished the same previously. The automatic keyboard avoidance behavior that was working as-expected prior to adding the new parameter has ceased. When I tap in the TextField now, the keyboard jumps up and covers it.

Has anyone else seen this?

Here's the code snippet in question:

                    TextField("", text: $cocktail.userNotes, axis: .vertical)
                       .placeHolder(Text("My notes"), show: cocktail.userNotes.isEmpty)
                       .autocapitalization(.sentences)
                       .padding(.vertical, 6)
                       .background(RoundedRectangle(cornerRadius: 4)
                          .strokeBorder(Color(profile.appData.colorTheme.accentColor),
                                        lineWidth: Constants.size.editBorderWidth))
                       .background(Color(profile.appData.colorTheme.editableTextFieldColor))

2      

I'm having the same issue and I didn't yet find any suitable solution...

4      

Having the same issue. What was your solution with a ZStack?

2      

I have the same issue with a TextEditor ...

I'm guessing this will work for both TextEditor and TextField with axis parameter: https://www.vadimbulavin.com/how-to-move-swiftui-view-when-keyboard-covers-text-field/

But I don't want to implement this just for just one TextEditor ... 🤨

2      

This solution worked for me when I had a TextField with axis vertical added. This site won't let me post the link that has the write up.

But here is the code example:

List(messages) { message in
    Text(message.text)
}
.safeAreaInset(edge: .bottom) {
    TextField(
        "New message",
        text: $newMessageText
    )
        .padding()
        .textFieldStyle(.roundedBorder)
        .background(.ultraThinMaterial)
        .onSubmit {
            // append message
        }
}

Put the TextField as a view in safeArea inset. Works great.

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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

Reply to this topic…

You need to create an account or log in to reply.

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.