A Swift package that adds a modifier .keyboardAware()
to SwiftUI views to handle the keyboard appearing:
Usage:
struct KeyboardAwareView: View {
@State var text = "example"
var body: some View {
NavigationView {
ScrollView {
VStack(alignment: .leading) {
ForEach(0 ..< 20) { i in
Text("Text \(i):")
TextField("Text", text: self.$text)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.bottom, 10)
}
}
.padding()
}
.keyboardAware() // <--- the view modifier
.navigationBarTitle("Keyboard Example")
}
}
}
Result: