Skip to content

Commit

Permalink
feat: try to de-attach input accessory view only when keyboard got cl…
Browse files Browse the repository at this point in the history
…osed (onMove handler still not precise)
  • Loading branch information
kirillzyusko committed Jan 14, 2025
1 parent c1fd2b9 commit d11afd6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
12 changes: 6 additions & 6 deletions example/src/screens/Examples/InteractiveKeyboardIOS/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions ios/interactive/InvisibleInputAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
15 changes: 7 additions & 8 deletions ios/observers/KeyboardMovementObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
///
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -314,7 +311,7 @@ public class KeyboardMovementObserver: NSObject {
}

if animation == nil {
initializeAnimation(fromValue: prevKeyboardPosition, toValue: keyboardHeight)
initializeAnimation(fromValue: prevKeyboardPosition, toValue: self._keyboardHeight)
}

prevKeyboardPosition = keyboardPosition
Expand All @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions ios/swizzling/UIResponderSwizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d11afd6

Please sign in to comment.