KeyboardSupport is set of SwiftUI modifiers to make your views keyboard-aware. Whether to get the software keyboard dimensions via .keyboardFrameProvider()
. Or by using .keyboardAware()
to automatically pull up a view whenever the keyboard pops in.
var body: some View {
VStack {
Spacer()
TextField("Keyboard-Aware Text Field", text: $value)
.keyboardAware()
}
.padding()
}
struct KeyboardHeightDisplay: View {
@Environment(\.keyboardFrame) var keyboardFrame
var body: some View {
Text("Current keyboard height: \(keyboardFrame.size.height)")
}
}
struct KeyboardHeightDisplay_Container: View {
var body: some View {
KeyboardHeightDisplay().keyboardFrameProvider()
}
}
More info in the docs.
In XCode add the following URL to your project's Swift Package dependencies:
https://github.com/swiftuilib/keyboard-support
To modify the package contents while still being able to see SwiftUI Previews use the provided KeyboardSupportPreview.xcodeproj
.