Skip to content

Instantly share code, notes, and snippets.

@michzio
Created May 4, 2020 16:56
Show Gist options
  • Save michzio/54388d0269d02ebd629f8e2b98bb19b6 to your computer and use it in GitHub Desktop.
Save michzio/54388d0269d02ebd629f8e2b98bb19b6 to your computer and use it in GitHub Desktop.
struct ScrollableView: View {
@State var value1: String = ""
@State var value2: String = ""
@ObservedObject var avoider = KeyboardAvoider()
var body: some View {
NavigationView {
List {
VStack(spacing: 8) {
ForEach(0..<15) { i in
Text("Text \(i)")
}
TextField("Field 1", text: self.$value1, onEditingChanged: { _ in
self.avoider.editingField = 1
})
// additional offset if keyboard is hiding this text field!
//.offset(y: self.avoider.slideSize.height != 0 ? 20 : 0)
.avoidKeyboard(tag: 1)
TextField("Field 2", text: self.$value2)
}
}
.attachKeyboardAvoider(avoider, offset: 32)
.padding(16)
.registerKeyboardAvoider(avoider)
}
.navigationBarTitle("Test", displayMode: .inline)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment