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.
package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt
CHANGED
|
@@ -156,7 +156,7 @@ class KeyboardAnimationCallback(
|
|
|
156
156
|
// then we need to reset the state
|
|
157
157
|
InteractiveKeyboardProvider.shown = false
|
|
158
158
|
}
|
|
159
|
-
|
|
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
|
-
|
|
99
|
+
setupKVObserver()
|
|
100
|
+
}
|
|
89
101
|
|
|
90
|
-
|
|
102
|
+
private func setupKVObserver() {
|
|
103
|
+
if hasKVObserver {
|
|
91
104
|
return
|
|
92
105
|
}
|
|
93
106
|
|
|
94
|
-
|
|
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
|
-
|
|
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