react-native-keyboard-controller 1.19.1 → 1.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ //
2
+ // NSObject.swift
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 26/10/2025.
6
+ //
7
+
8
+ public extension NSObject {
9
+ func safeValue(forKey key: String) -> Any? {
10
+ return _safeValue(forKey: key)
11
+ }
12
+ }
@@ -30,11 +30,7 @@ public extension Optional where Wrapped == UIResponder {
30
30
  guard let superview = (self as? UIView)?.superview else { return nil }
31
31
 
32
32
  #if KEYBOARD_CONTROLLER_NEW_ARCH_ENABLED
33
- if superview.responds(to: Selector(("nativeId"))) == true {
34
- return (superview as NSObject).value(forKey: "nativeId") as? String
35
- }
36
-
37
- return nil
33
+ return superview.safeValue(forKey: "nativeId") as? String
38
34
  #else
39
35
  return superview.nativeID
40
36
  #endif
@@ -11,10 +11,13 @@ import UIKit
11
11
 
12
12
  public extension UITextInput {
13
13
  var canSelectionFitIntoLayout: Bool {
14
- guard let textView = self as? UITextView else { return true }
15
-
16
- // Force layout to ensure accurate rect calculation
17
- textView.layoutManager.ensureLayout(for: textView.textContainer)
14
+ if let selfObj = self as? NSObject,
15
+ let delegate = selfObj.safeValue(forKey: "textInputDelegate") as? NSObject,
16
+ let comingFromJS = delegate.safeValue(forKey: "_comingFromJS") as? Bool,
17
+ comingFromJS
18
+ {
19
+ return false
20
+ }
18
21
 
19
22
  guard let selectedRange = selectedTextRange else { return false }
20
23
 
@@ -0,0 +1,12 @@
1
+ //
2
+ // NSObject+SafeKVC.h
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 26/10/2025.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+
10
+ @interface NSObject (SafeKVC)
11
+ - (id)_safeValueForKey:(NSString *)key;
12
+ @end
@@ -0,0 +1,19 @@
1
+ //
2
+ // NSObject+SafeKVC.m
3
+ // KeyboardController
4
+ //
5
+ // Created by Kiryl Ziusko on 26/10/2025.
6
+ //
7
+
8
+ #import "NSObject+SafeKVC.h"
9
+
10
+ @implementation NSObject (SafeKVC)
11
+ - (id)_safeValueForKey:(NSString *)key
12
+ {
13
+ @try {
14
+ return [self valueForKey:key];
15
+ } @catch (NSException *exception) {
16
+ return nil;
17
+ }
18
+ }
19
+ @end
@@ -15,6 +15,7 @@ final class KeyboardTrackingView: UIView {
15
15
  private var keyboardView: UIView? { KeyboardViewLocator.shared.resolve() }
16
16
  private var keyboardHeight = 0.0
17
17
  private weak var currentAttachedView: UIView?
18
+ private var isAttaching = false
18
19
 
19
20
  static let invalidPosition: CGFloat = -.greatestFiniteMagnitude
20
21
 
@@ -55,12 +56,14 @@ final class KeyboardTrackingView: UIView {
55
56
  name: UIResponder.keyboardDidShowNotification,
56
57
  object: nil
57
58
  )
58
- NotificationCenter.default.addObserver(
59
- self,
60
- selector: #selector(attachToTopmostView),
61
- name: UIWindow.didBecomeVisibleNotification,
62
- object: nil
63
- )
59
+ attachToTopmostView()
60
+ }
61
+
62
+ override func willMove(toWindow newWindow: UIWindow?) {
63
+ // When the view is being removed from the window, we need to re-attach it
64
+ if newWindow == nil, !isAttaching {
65
+ attachToTopmostView()
66
+ }
64
67
  }
65
68
 
66
69
  @objc private func attachToTopmostView() {
@@ -68,6 +71,7 @@ final class KeyboardTrackingView: UIView {
68
71
 
69
72
  if currentAttachedView === topView { return }
70
73
 
74
+ isAttaching = true
71
75
  removeFromSuperview()
72
76
 
73
77
  topView.addSubview(self)
@@ -87,6 +91,7 @@ final class KeyboardTrackingView: UIView {
87
91
  heightAnchor.constraint(equalToConstant: 0),
88
92
  ])
89
93
  }
94
+ isAttaching = false
90
95
  }
91
96
 
92
97
  @objc private func keyboardWillAppear(_ notification: Notification) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.19.1",
3
+ "version": "1.19.3",
4
4
  "description": "Keyboard manager which works in identical way on both iOS and Android",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -40,7 +40,7 @@
40
40
  "test": "jest",
41
41
  "typescript": "tsc --noEmit --project tsconfig.build.json",
42
42
  "lint": "eslint --quiet \"**/*.{js,ts,tsx}\"",
43
- "lint-clang": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i -n --Werror",
43
+ "lint-clang": "find ios/ -iname *.h -o -iname *.m -o -iname *.mm | grep -v -e Pods -e build | xargs clang-format -i --Werror",
44
44
  "prepare": "bob build > /dev/null 2>&1",
45
45
  "release": "release-it",
46
46
  "example": "yarn --cwd example",