Skip to content

Commit

Permalink
fix: grow of input breaks onInteractive handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 12, 2024
1 parent 9f9bd0d commit b9603fc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- (x) close after interactive gesture - sudden jump of 75 pixels -> fixed by detaching iav during `onInteractive`
- (x) keyboard hidden -> remove inputAccessoryView - done in resignFirstResponder
- (x) iOS 16 - after attaching fake iav we dispatch onEnd with height - 248 (298 - 50) -> ignore events after attaching iav, because in keyboardDidAppear `position` can be a random value (291 or 341)
- (x) text input grow -> can not make interactive gesture (Optional(424.6666666666667) 424.66666666666674) - maybe because of frequent conversions to CGFloat? <- fixed via rounding
- show after interactive - keyboard height is 386
- text input grow -> can not make interactive gesture (Optional(424.6666666666667) 424.66666666666674) - maybe because of frequent conversions to CGFloat?
5 changes: 5 additions & 0 deletions ios/interactive/InvisibleInputAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class InvisibleInputAccessoryView: UIView {
layoutIfNeeded()
}

public func hide() {
updateHeight(to: 0.0)
superview?.layoutIfNeeded()
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: frame.height)
}
Expand Down
5 changes: 2 additions & 3 deletions ios/observers/KeyboardMovementObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class KeyboardMovementObserver: NSObject {
print("\(keyboardView?.bounds.size.height) \(_keyboardHeight)")
// if keyboard height is not equal to its bounds - we can ignore
// values, since they'll be invalid and will cause UI jumps
if (keyboardView?.bounds.size.height ?? 0) != _keyboardHeight {
if floor(keyboardView?.bounds.size.height ?? 0) != floor(_keyboardHeight) {
return
}

Expand All @@ -164,8 +164,7 @@ public class KeyboardMovementObserver: NSObject {

prevKeyboardPosition = position
// TODO: needs here? Why in onStart/onEnd after interactive gesture we get keyboard height as 386?

Check failure on line 166 in ios/observers/KeyboardMovementObserver.swift

View workflow job for this annotation

GitHub Actions / 🔎 Swift Lint

Todo Violation: TODOs should be resolved (needs here? Why in onStart/onE...) (todo)
(UIResponder.current?.inputAccessoryView as? InvisibleInputAccessoryView)?.updateHeight(to: 0)
UIResponder.current?.inputAccessoryView?.superview?.layoutIfNeeded()
(UIResponder.current?.inputAccessoryView as? InvisibleInputAccessoryView)?.hide()
///
onEvent(
"onKeyboardMoveInteractive",
Expand Down
3 changes: 1 addition & 2 deletions ios/swizzling/UIResponderSwizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ extension UIResponder {
print("Performing custom actions before the original resignFirstResponder")

if let textField = self as? TextInput {
(textField.inputAccessoryView as? InvisibleInputAccessoryView)?.updateHeight(to: 0)
textField.inputAccessoryView?.superview?.layoutIfNeeded()
(textField.inputAccessoryView as? InvisibleInputAccessoryView)?.hide()
}

// Postpone execution of the original resignFirstResponder
Expand Down

0 comments on commit b9603fc

Please sign in to comment.