From e178939604e1d34640e379d96da1e80897c602a6 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Mon, 30 Dec 2024 18:49:33 -0500 Subject: [PATCH] Manually constrain bottomAnchor to match animation --- .../ios/KeyboardAvoidingView.swift | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/modules/keyboard-avoiding-view/ios/KeyboardAvoidingView.swift b/modules/keyboard-avoiding-view/ios/KeyboardAvoidingView.swift index be897d0..b731dac 100644 --- a/modules/keyboard-avoiding-view/ios/KeyboardAvoidingView.swift +++ b/modules/keyboard-avoiding-view/ios/KeyboardAvoidingView.swift @@ -8,8 +8,11 @@ class KeyboardAvoidingView: ExpoView { private var scrollView: ScrollViewWrapper? private var animationInProgress = false private var measurerHasObserver = false + private var containerBottomAnchor: NSLayoutConstraint required init(appContext: AppContext? = nil) { + containerBottomAnchor = container.bottomAnchor.constraint(equalTo: bottomAnchor) + super.init(appContext: appContext) addSubview(measurer) @@ -30,7 +33,7 @@ class KeyboardAvoidingView: ExpoView { container.heightAnchor.constraint(equalTo: heightAnchor), container.leadingAnchor.constraint(equalTo: leadingAnchor), container.trailingAnchor.constraint(equalTo: trailingAnchor), - container.bottomAnchor.constraint(equalTo: keyboardLayoutGuide.topAnchor), + containerBottomAnchor, ]) NotificationCenter.default.addObserver( @@ -53,17 +56,6 @@ class KeyboardAvoidingView: ExpoView { name: UIResponder.keyboardWillHideNotification, object: nil ) - - NotificationCenter.default.addObserver( - self, - selector: #selector(keyboardDidHide), - name: UIResponder.keyboardDidHideNotification, - object: nil - ) - - if #available(iOS 17.0, *) { - keyboardLayoutGuide.usesBottomSafeArea = false - } } deinit { @@ -73,7 +65,6 @@ class KeyboardAvoidingView: ExpoView { } @objc private func keyboardWillShow(_ notification: Notification) { - keyboardLayoutGuide.followsUndockedKeyboard = true updateInsets(notification) } @@ -105,6 +96,8 @@ class KeyboardAvoidingView: ExpoView { withDuration: animationDuration, delay: 0.0, options: animationOptions, animations: { self.scrollView?.setInsetsFromKeyboardHeight(keyboardHeight) + self.containerBottomAnchor.constant = -keyboardHeight + self.container.layoutIfNeeded() }, completion: { finished in self.animationInProgress = false @@ -119,10 +112,6 @@ class KeyboardAvoidingView: ExpoView { updateInsets(notification, closing: true) } - @objc private func keyboardDidHide(_ notification: Notification) { - keyboardLayoutGuide.followsUndockedKeyboard = false - } - @objc override public func observeValue( forKeyPath keyPath: String?, of object: Any?, @@ -133,7 +122,9 @@ class KeyboardAvoidingView: ExpoView { if animationInProgress { return } - self.scrollView?.setInsetsFromKeyboardHeight(measurer.frame.height) + scrollView?.setInsetsFromKeyboardHeight(measurer.frame.height) + containerBottomAnchor.constant = measurer.frame.height + container.layoutIfNeeded() } }