react-native-keyboard-controller 1.16.0 → 1.16.1
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.
|
@@ -49,7 +49,11 @@ public extension Optional where Wrapped == UIResponder {
|
|
|
49
49
|
guard let superview = (self as? UIView)?.superview else { return nil }
|
|
50
50
|
|
|
51
51
|
#if KEYBOARD_CONTROLLER_NEW_ARCH_ENABLED
|
|
52
|
-
|
|
52
|
+
if superview.responds(to: Selector(("nativeId"))) == true {
|
|
53
|
+
return (superview as NSObject).value(forKey: "nativeId") as? String
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return nil
|
|
53
57
|
#else
|
|
54
58
|
return superview.nativeID
|
|
55
59
|
#endif
|
|
@@ -33,7 +33,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
33
33
|
private var _windowsCount: Int = 0
|
|
34
34
|
private var prevKeyboardPosition = 0.0
|
|
35
35
|
private var displayLink: CADisplayLink?
|
|
36
|
-
private var
|
|
36
|
+
private var interactiveKeyboardObserver: NSKeyValueObservation?
|
|
37
37
|
private var isMounted = false
|
|
38
38
|
// state variables
|
|
39
39
|
private var _keyboardHeight: CGFloat = 0.0
|
|
@@ -93,73 +93,57 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
private func setupKVObserver() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
guard interactiveKeyboardObserver == nil, let view = keyboardView else { return }
|
|
97
|
+
|
|
98
|
+
interactiveKeyboardObserver = view.observe(\.center, options: .new) { [weak self] _, change in
|
|
99
|
+
guard let self = self, let changeValue = change.newValue else { return }
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
hasKVObserver = true
|
|
102
|
-
keyboardView?.addObserver(self, forKeyPath: "center", options: .new, context: nil)
|
|
101
|
+
self.keyboardDidMoveInteractively(changeValue: changeValue)
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
private func removeKVObserver() {
|
|
107
|
-
|
|
106
|
+
interactiveKeyboardObserver?.invalidate()
|
|
107
|
+
interactiveKeyboardObserver = nil
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private func keyboardDidMoveInteractively(changeValue: CGPoint) {
|
|
111
|
+
// if we are currently animating keyboard -> we need to ignore values from KVO
|
|
112
|
+
if displayLink != nil {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
// if keyboard height is not equal to its bounds - we can ignore
|
|
116
|
+
// values, since they'll be invalid and will cause UI jumps
|
|
117
|
+
if floor(keyboardView?.bounds.size.height ?? 0) != floor(_keyboardHeight) {
|
|
108
118
|
return
|
|
109
119
|
}
|
|
110
120
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
let keyboardFrameY = changeValue.y
|
|
122
|
+
let keyboardWindowH = keyboardView?.window?.bounds.size.height ?? 0
|
|
123
|
+
let keyboardPosition = keyboardWindowH - keyboardFrameY
|
|
114
124
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
context _: UnsafeMutableRawPointer?
|
|
121
|
-
) {
|
|
122
|
-
if keyPath == "center", object as? NSObject == _keyboardView {
|
|
123
|
-
// if we are currently animating keyboard -> we need to ignore values from KVO
|
|
124
|
-
if displayLink != nil {
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
// if keyboard height is not equal to its bounds - we can ignore
|
|
128
|
-
// values, since they'll be invalid and will cause UI jumps
|
|
129
|
-
if floor(keyboardView?.bounds.size.height ?? 0) != floor(_keyboardHeight) {
|
|
130
|
-
return
|
|
131
|
-
}
|
|
125
|
+
let position = CGFloat.interpolate(
|
|
126
|
+
inputRange: [_keyboardHeight / 2, -_keyboardHeight / 2],
|
|
127
|
+
outputRange: [_keyboardHeight, 0],
|
|
128
|
+
currentValue: keyboardPosition
|
|
129
|
+
) - KeyboardAreaExtender.shared.offset
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
let position = CGFloat.interpolate(
|
|
141
|
-
inputRange: [_keyboardHeight / 2, -_keyboardHeight / 2],
|
|
142
|
-
outputRange: [_keyboardHeight, 0],
|
|
143
|
-
currentValue: keyboardPosition
|
|
144
|
-
) - KeyboardAreaExtender.shared.offset
|
|
145
|
-
|
|
146
|
-
if position == 0 {
|
|
147
|
-
// it will be triggered before `keyboardWillDisappear` and
|
|
148
|
-
// we don't need to trigger `onInteractive` handler for that
|
|
149
|
-
// since it will be handled in `keyboardWillDisappear` function
|
|
150
|
-
return
|
|
151
|
-
}
|
|
131
|
+
if position == 0 {
|
|
132
|
+
// it will be triggered before `keyboardWillDisappear` and
|
|
133
|
+
// we don't need to trigger `onInteractive` handler for that
|
|
134
|
+
// since it will be handled in `keyboardWillDisappear` function
|
|
135
|
+
return
|
|
136
|
+
}
|
|
152
137
|
|
|
153
|
-
|
|
138
|
+
prevKeyboardPosition = position
|
|
154
139
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
140
|
+
onEvent(
|
|
141
|
+
"onKeyboardMoveInteractive",
|
|
142
|
+
position as NSNumber,
|
|
143
|
+
position / CGFloat(keyboardHeight) as NSNumber,
|
|
144
|
+
-1,
|
|
145
|
+
tag
|
|
146
|
+
)
|
|
163
147
|
}
|
|
164
148
|
|
|
165
149
|
@objc public func unmount() {
|
package/package.json
CHANGED