From d11afd6562090f9a45665bbc324d414003d8c428 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 26 Nov 2024 15:27:09 +0100 Subject: [PATCH] feat: try to de-attach input accessory view only when keyboard got closed (onMove handler still not precise) --- .../Examples/InteractiveKeyboardIOS/index.tsx | 12 ++++++------ ios/interactive/InvisibleInputAccessoryView.swift | 4 ++-- ios/observers/KeyboardMovementObserver.swift | 15 +++++++-------- ios/swizzling/UIResponderSwizzle.swift | 3 --- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/example/src/screens/Examples/InteractiveKeyboardIOS/index.tsx b/example/src/screens/Examples/InteractiveKeyboardIOS/index.tsx index 282cfa2019..7784affc10 100644 --- a/example/src/screens/Examples/InteractiveKeyboardIOS/index.tsx +++ b/example/src/screens/Examples/InteractiveKeyboardIOS/index.tsx @@ -43,8 +43,8 @@ const useKeyboardAnimation = () => { return; } - progress.value = e.progress; - height.value = e.height; + // progress.value = e.progress; + // height.value = e.height; inset.value = e.height; // Math.max is needed to prevent overscroll when keyboard hides (and user scrolled to the top, for example) @@ -59,10 +59,10 @@ const useKeyboardAnimation = () => { onMove: (e) => { "worklet"; - if (shouldUseOnMoveHandler.value) { - progress.value = e.progress; - height.value = e.height; - } + // if (shouldUseOnMoveHandler.value) { + progress.value = e.progress; + height.value = e.height; + // } }, onEnd: (e) => { "worklet"; diff --git a/ios/interactive/InvisibleInputAccessoryView.swift b/ios/interactive/InvisibleInputAccessoryView.swift index c9e6ab04e3..fe0ab57fc1 100644 --- a/ios/interactive/InvisibleInputAccessoryView.swift +++ b/ios/interactive/InvisibleInputAccessoryView.swift @@ -53,8 +53,8 @@ public class InvisibleInputAccessoryView: UIView { private func setupView() { isUserInteractionEnabled = false // TODO: Set the background color to transparent - backgroundColor = UIColor.red - // backgroundColor = .clear + // backgroundColor = UIColor.red.withAlphaComponent(0.2) + backgroundColor = .clear autoresizingMask = .flexibleHeight } } diff --git a/ios/observers/KeyboardMovementObserver.swift b/ios/observers/KeyboardMovementObserver.swift index 2e044e8de4..ba415456f5 100644 --- a/ios/observers/KeyboardMovementObserver.swift +++ b/ios/observers/KeyboardMovementObserver.swift @@ -166,10 +166,6 @@ public class KeyboardMovementObserver: NSObject { -1, tag ) - - // TODO: needs here? Why in onStart/onEnd after interactive gesture we get keyboard height as 386? - KeyboardAreaExtender.shared.hide() - /// } } @@ -215,7 +211,8 @@ public class KeyboardMovementObserver: NSObject { setupKeyboardWatcher() removeKVObserver() - initializeAnimation(fromValue: prevKeyboardPosition, toValue: 0) + initializeAnimation( + fromValue: prevKeyboardPosition + KeyboardAreaExtender.shared.offset, toValue: 0) } @objc func keyboardDidAppear(_ notification: Notification) { @@ -237,7 +234,7 @@ public class KeyboardMovementObserver: NSObject { // so we just read actual keyboard frame value in this case let height = timestamp >= didShowDeadline - ? self.keyboardHeight : position + ? self.keyboardHeight : position - KeyboardAreaExtender.shared.offset print("Using \(timestamp >= didShowDeadline ? "self.keyboardHeight" : "position")") print("\(timestamp) vs \(didShowDeadline)") // always limit progress to the maximum possible value @@ -314,7 +311,7 @@ public class KeyboardMovementObserver: NSObject { } if animation == nil { - initializeAnimation(fromValue: prevKeyboardPosition, toValue: keyboardHeight) + initializeAnimation(fromValue: prevKeyboardPosition, toValue: self._keyboardHeight) } prevKeyboardPosition = keyboardPosition @@ -338,7 +335,9 @@ public class KeyboardMovementObserver: NSObject { // handles a case when final frame has final destination (i. e. 0 or 291) // but CASpringAnimation can never get to this final destination let race: (CGFloat, CGFloat) -> CGFloat = animation.isIncreasing ? max : min - keyboardPosition = race(position, keyboardPosition) + keyboardPosition = race(position, keyboardPosition) - KeyboardAreaExtender.shared.offset + + print("\(visibleKeyboardHeight) -> \(position)") } onEvent( diff --git a/ios/swizzling/UIResponderSwizzle.swift b/ios/swizzling/UIResponderSwizzle.swift index c2668171e6..3ffa7fdba6 100644 --- a/ios/swizzling/UIResponderSwizzle.swift +++ b/ios/swizzling/UIResponderSwizzle.swift @@ -31,9 +31,6 @@ extension UIResponder { print("Performing custom actions before the original resignFirstResponder") KeyboardAreaExtender.shared.hide() - // if let textField = self as? TextInput { - // (textField.inputAccessoryView as? InvisibleInputAccessoryView)?.hide() - // } // Postpone execution of the original resignFirstResponder DispatchQueue.main.asyncAfter(deadline: .now() + UIUtils.nextFrame) {