How is it possible to show the complete List when the keyboard is showing up? The keyboard is hiding the lower part of the list.
I have a textField in my list row. W
there is an answer here to handle keyboard actions, you can subscribe for keyboard events like this:
final class KeyboardResponder: BindableObject {
let didChange = PassthroughSubject()
private var _center: NotificationCenter
private(set) var currentHeight: CGFloat = 0 {
didSet {
didChange.send(currentHeight)
}
}
init(center: NotificationCenter = .default) {
_center = center
_center.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
_center.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
deinit {
_center.removeObserver(self)
}
@objc func keyBoardWillShow(notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
currentHeight = keyboardSize.height
}
}
@objc func keyBoardWillHide(notification: Notification) {
currentHeight = 0
}
}
and then just use it like this:
@State var keyboard = KeyboardResponder()
var body: some View {
List {
VStack {
...
...
...
}.padding(.bottom, keyboard.currentHeight)
}