Skip to content

tjdrhs90/swiftui-keyboard-avoider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUI Keyboard Avoider

Swift 5.9 iOS 14+ SPM License

A simple SwiftUI modifier that automatically moves your view when the keyboard appears. One line. No boilerplate.

Installation

Add this package via Swift Package Manager:

https://github.com/tjdrhs90/swiftui-keyboard-avoider.git

Or add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/tjdrhs90/swiftui-keyboard-avoider.git", from: "1.0.0")
]

Usage

import KeyboardAvoider

struct LoginView: View {
    @State private var email = ""
    @State private var password = ""

    var body: some View {
        VStack(spacing: 16) {
            TextField("Email", text: $email)
                .textFieldStyle(.roundedBorder)

            SecureField("Password", text: $password)
                .textFieldStyle(.roundedBorder)

            Button("Sign In") { }
        }
        .padding()
        .keyboardAvoider() // ← Just add this
    }
}

That's it. The view automatically adds bottom padding with a smooth animation when the keyboard appears, and removes it when the keyboard hides.

Requirements

  • iOS 14+
  • Swift 5.9+
  • Xcode 15+

License

MIT License. See LICENSE for details.

About

A simple SwiftUI modifier that automatically moves your view when the keyboard appears

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages