https://github.com/eneskaraosman/keyboardactions
KeyboardActions is a SwiftUI package that allows you to manage the focus of the keyboard in your app. Adds toolbar item above keyboard to easily switch focus between textfields or close keyboard
https://github.com/eneskaraosman/keyboardactions
focus-scope keyboard-toolbar swift-package-manager swiftui
Last synced: 3 months ago
JSON representation
KeyboardActions is a SwiftUI package that allows you to manage the focus of the keyboard in your app. Adds toolbar item above keyboard to easily switch focus between textfields or close keyboard
- Host: GitHub
- URL: https://github.com/eneskaraosman/keyboardactions
- Owner: EnesKaraosman
- Created: 2024-04-01T14:40:17.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-01T14:49:57.000Z (about 1 year ago)
- Last Synced: 2025-01-19T20:15:06.355Z (5 months ago)
- Topics: focus-scope, keyboard-toolbar, swift-package-manager, swiftui
- Language: Swift
- Homepage:
- Size: 979 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# KeyboardActions
KeyboardActions is a SwiftUI package that allows you to manage the focus of the keyboard in your app. Adds toolbar item above keyboard to easily switch focus between textfields or close keyboard
You can create an enumeration that represents your fields in a form. Confirm `FieldContract` which is basically a `Hashable` protocol currently
And add `.keyboardActions` modifier to your view to enable the toolbar above the keyboard
```swift
import KeyboardActions
import SwiftUIstruct ContentView: View {
@State private var mail: String = ""
@State private var password: String = ""
@State private var confirmPassword: String = ""enum Field: CaseIterable, FieldContract {
case mail
case password
case confirmPassword
}@FocusState var focusedField: Field?
var body: some View {
VStack {
TextField("Mail", text: $mail)
.focused($focusedField, equals: Field.mail)
.padding(4)
.border(.gray)TextField("Password", text: $password)
.focused($focusedField, equals: Field.password)
.padding(4)
.border(.gray)TextField("Confirm Password", text: $confirmPassword)
.focused($focusedField, equals: Field.confirmPassword)
.padding(4)
.border(.gray)
}
.padding()
.keyboardActions(focusedField: $focusedField, fields: Field.allCases)
.onAppear {
focusedField = Field.mail
}
}
}
```
![]()