Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelhenry/keyboardavoider
The missing interactive keyboard in SwiftUI for iOS
https://github.com/michaelhenry/keyboardavoider
autodismisskeyboard autokeyboard ios keyboard swiftui
Last synced: about 2 months ago
JSON representation
The missing interactive keyboard in SwiftUI for iOS
- Host: GitHub
- URL: https://github.com/michaelhenry/keyboardavoider
- Owner: michaelhenry
- License: mit
- Created: 2020-01-08T06:45:32.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T03:29:04.000Z (almost 5 years ago)
- Last Synced: 2024-09-19T05:02:20.618Z (3 months ago)
- Topics: autodismisskeyboard, autokeyboard, ios, keyboard, swiftui
- Language: Swift
- Homepage:
- Size: 3.24 MB
- Stars: 129
- Watchers: 5
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Screenshot](images/screenshot.gif) ![Screenshot](images/screenshot2.gif)
[![Deployment status](https://github.com/michaelhenry/KeyboardAvoider/workflows/deploy_to_cocoapods/badge.svg)](https://github.com/michaelhenry/KeyboardAvoider/actions)
[![Version](https://img.shields.io/cocoapods/v/KeyboardAvoider.svg?style=flat)](https://cocoapods.org/pods/KeyboardAvoider)
[![License](https://img.shields.io/cocoapods/l/KeyboardAvoider.svg?style=flat)](https://cocoapods.org/pods/KeyboardAvoider)
[![Platform](https://img.shields.io/cocoapods/p/KeyboardAvoider.svg?style=flat)](https://cocoapods.org/pods/KeyboardAvoider)# ⌨️ KeyboardAvoider {}
A **KeyboardAvoider** for SwiftUI. Inspired by the simplicity of [keyboard_avoider](https://pub.dev/packages/keyboard_avoider) in [Flutter](https://flutter.dev/).
## Features
- Autoscroll to TextField
- Swipe keyboard to dismiss## Installation
### [Swift Package Manager](https://github.com/apple/swift-package-manager)
Create a `Package.swift` file.
```swift
import PackageDescriptionlet package = Package(
name: "TestProject",
dependencies: [
.package(url: "https://github.com/michaelhenry/KeyboardAvoider.git", from: "1.0.0")
]
)
```### Cocoapods
```ruby
target 'MyApp' do
pod 'KeyboardAvoider', '~> 1.0'
end
```## How to use
```swift
import KeyboardAvoiderKeyboardAvoider {
// ... Your view with TextFields
}
```Example:
```swift
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.
```swift
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](https://github.com/michaelhenry/KeyboardAvoider/blob/d5293c541673bce47f00cdd0ec2f1b604b5341c8/KeyboardAvoider-Example/KeyboardAvoider-Example/ContentView.swift#L45)
```swift
.edgesIgnoringSafeArea(.bottom)
```