The missing interactive keyboard in SwiftUI for iOS

KeyboardAvoider {}

A KeyboardAvoider for SwiftUI. Inspired by the simplicity of keyboard_avoider in Flutter.

Installation

Swift Package Manager

Create a Package.swift file.

import PackageDescription

let package = Package(
  name: "TestProject",
  dependencies: [
    .package(url: "https://github.com/michaelhenry/KeyboardAvoider.git", from: "1.0.0")
  ]
)

Cocoapods

target 'MyApp' do
  pod 'KeyboardAvoider', '~> 1.0'
end

How to use

import KeyboardAvoider

KeyboardAvoider {
  // ... Your view with TextFields
}

Example:

KeyboardAvoider {
    VStack {
        TextField("First name", text: self.$firstname)
        TextField("Last name", text: self.$lastname)
        TextField("Email", text: self.$email)
        TextField("Password", text: self.$password)
        TextField("Confirm password", text: self.$password)
        Button("Sign Up") {

        }
        Button("Already have an account?") {

        }
    }
    .padding(.horizontal, 16.0)
}

FAQ

  • How to remove the extra space between the textfield and the keyboard

    You can remove it by ignoring the safe area layout - bottom. Please see the Sample Project

 .edgesIgnoringSafeArea(.bottom)

GitHub