Created
May 4, 2020 16:56
-
-
Save michzio/54388d0269d02ebd629f8e2b98bb19b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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