react-native-keyboard-controller 1.5.1 → 1.5.2

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.
@@ -156,7 +156,7 @@ class KeyboardAnimationCallback(
156
156
  // then we need to reset the state
157
157
  InteractiveKeyboardProvider.shown = false
158
158
  }
159
- val isKeyboardVisible = isKeyboardVisible || isKeyboardShown
159
+ isKeyboardVisible = isKeyboardVisible || isKeyboardShown
160
160
 
161
161
  this.emitEvent("KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", getEventParams(this.persistentKeyboardHeight))
162
162
  this.sendEventToJS(KeyboardTransitionEvent(view.id, "topKeyboardMoveEnd", this.persistentKeyboardHeight, if (!isKeyboardVisible) 0.0 else 1.0))
@@ -42,6 +42,7 @@ public class KeyboardMovementObserver: NSObject {
42
42
  private var prevKeyboardPosition = 0.0
43
43
  private var displayLink: CADisplayLink?
44
44
  private var keyboardHeight: CGFloat = 0.0
45
+ private var hasKVObserver = false
45
46
 
46
47
  @objc public init(
47
48
  handler: @escaping (NSString, NSNumber, NSNumber) -> Void,
@@ -82,18 +83,40 @@ public class KeyboardMovementObserver: NSObject {
82
83
  name: UIWindow.didBecomeVisibleNotification,
83
84
  object: nil
84
85
  )
86
+ NotificationCenter.default.addObserver(
87
+ self,
88
+ selector: #selector(windowDidBecomeHidden),
89
+ name: UIWindow.didBecomeHiddenNotification,
90
+ object: nil
91
+ )
92
+ }
93
+
94
+ @objc func windowDidBecomeHidden(_: Notification) {
95
+ removeKVObserver()
85
96
  }
86
97
 
87
98
  @objc func windowDidBecomeVisible(_: Notification) {
88
- let keyboardView = findKeyboardView()
99
+ setupKVObserver()
100
+ }
89
101
 
90
- if keyboardView == _keyboardView {
102
+ private func setupKVObserver() {
103
+ if hasKVObserver {
91
104
  return
92
105
  }
93
106
 
94
- _keyboardView = keyboardView
107
+ if keyboardView != nil {
108
+ hasKVObserver = true
109
+ keyboardView?.addObserver(self, forKeyPath: "center", options: .new, context: nil)
110
+ }
111
+ }
112
+
113
+ private func removeKVObserver() {
114
+ if !hasKVObserver {
115
+ return
116
+ }
95
117
 
96
- keyboardView?.addObserver(self, forKeyPath: "center", options: .new, context: nil)
118
+ hasKVObserver = false
119
+ keyboardView?.removeObserver(self, forKeyPath: "center", context: nil)
97
120
  }
98
121
 
99
122
  // swiftlint:disable:next block_based_kvo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
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",