Swiftpack.co - Package - michaelhenry/KeyboardAvoider

Screenshot Screenshot

Deployment status Version License Platform

⌨️ KeyboardAvoider {}

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

Features

  • Autoscroll to TextField
  • Swipe keyboard to dismiss

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)
}

Or in case you don't want to make your view scrollable, you can just only apply the .avoidKeyboard() into your main view.

    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?") {

        }
    }
    .avoidKeyboard()

FAQ

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

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

 .edgesIgnoringSafeArea(.bottom)

Github

link
Stars: 89

Dependencies

Used By

Total: 0

Releases

bugfix: space between input field and keyboard - 2020-01-29 03:29:04

Added space between keyboard and input field - 2020-01-22 23:24:39

Refactor: Removed ScrollViewX - 2020-01-10 17:14:22