react-native-keyboard-controller 1.13.1 → 1.13.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.
|
@@ -40,6 +40,7 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
40
40
|
private var duration = 0
|
|
41
41
|
private var tag: NSNumber = -1
|
|
42
42
|
private var animation: KeyboardAnimation?
|
|
43
|
+
private var didShowDeadline: Int64 = 0
|
|
43
44
|
|
|
44
45
|
@objc public init(
|
|
45
46
|
handler: @escaping (NSString, NSNumber, NSNumber, NSNumber, NSNumber) -> Void,
|
|
@@ -162,24 +163,17 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
@objc func keyboardWillAppear(_ notification: Notification) {
|
|
165
|
-
|
|
166
|
+
let (duration, frame) = metaDataFromNotification(notification)
|
|
167
|
+
if let keyboardFrame = frame {
|
|
166
168
|
tag = UIResponder.current.reactViewTag
|
|
167
169
|
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
168
|
-
let duration = Int(
|
|
169
|
-
(notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double ?? 0) * 1000
|
|
170
|
-
)
|
|
171
170
|
self.keyboardHeight = keyboardHeight
|
|
172
171
|
self.duration = duration
|
|
173
|
-
|
|
174
|
-
var data = [AnyHashable: Any]()
|
|
175
|
-
data["height"] = keyboardHeight
|
|
176
|
-
data["duration"] = duration
|
|
177
|
-
data["timestamp"] = Date.currentTimeStamp
|
|
178
|
-
data["target"] = tag
|
|
172
|
+
didShowDeadline = Date.currentTimeStamp + Int64(duration)
|
|
179
173
|
|
|
180
174
|
onRequestAnimation()
|
|
181
175
|
onEvent("onKeyboardMoveStart", Float(keyboardHeight) as NSNumber, 1, duration as NSNumber, tag)
|
|
182
|
-
onNotify("KeyboardController::keyboardWillShow",
|
|
176
|
+
onNotify("KeyboardController::keyboardWillShow", getEventParams(keyboardHeight, duration))
|
|
183
177
|
|
|
184
178
|
setupKeyboardWatcher()
|
|
185
179
|
initializeAnimation(fromValue: prevKeyboardPosition, toValue: keyboardHeight)
|
|
@@ -187,21 +181,13 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
187
181
|
}
|
|
188
182
|
|
|
189
183
|
@objc func keyboardWillDisappear(_ notification: Notification) {
|
|
190
|
-
let duration =
|
|
191
|
-
(notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double ?? 0) * 1000
|
|
192
|
-
)
|
|
184
|
+
let (duration, _) = metaDataFromNotification(notification)
|
|
193
185
|
tag = UIResponder.current.reactViewTag
|
|
194
186
|
self.duration = duration
|
|
195
187
|
|
|
196
|
-
var data = [AnyHashable: Any]()
|
|
197
|
-
data["height"] = 0
|
|
198
|
-
data["duration"] = duration
|
|
199
|
-
data["timestamp"] = Date.currentTimeStamp
|
|
200
|
-
data["target"] = tag
|
|
201
|
-
|
|
202
188
|
onRequestAnimation()
|
|
203
189
|
onEvent("onKeyboardMoveStart", 0, 0, duration as NSNumber, tag)
|
|
204
|
-
onNotify("KeyboardController::keyboardWillHide",
|
|
190
|
+
onNotify("KeyboardController::keyboardWillHide", getEventParams(0, duration))
|
|
205
191
|
|
|
206
192
|
setupKeyboardWatcher()
|
|
207
193
|
removeKVObserver()
|
|
@@ -209,26 +195,22 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
209
195
|
}
|
|
210
196
|
|
|
211
197
|
@objc func keyboardDidAppear(_ notification: Notification) {
|
|
212
|
-
|
|
198
|
+
let timestamp = Date.currentTimeStamp
|
|
199
|
+
let (duration, frame) = metaDataFromNotification(notification)
|
|
200
|
+
if let keyboardFrame = frame {
|
|
213
201
|
let (position, _) = keyboardView.framePositionInWindow
|
|
214
202
|
let keyboardHeight = keyboardFrame.cgRectValue.size.height
|
|
215
203
|
tag = UIResponder.current.reactViewTag
|
|
216
204
|
self.keyboardHeight = keyboardHeight
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
205
|
+
// if the event is caught in between it's highly likely that it could be a "resize" event
|
|
206
|
+
// so we just read actual keyboard frame value in this case
|
|
207
|
+
let height = timestamp >= didShowDeadline ? keyboardHeight : position
|
|
220
208
|
// always limit progress to the maximum possible value
|
|
221
|
-
let progress = min(
|
|
222
|
-
|
|
223
|
-
var data = [AnyHashable: Any]()
|
|
224
|
-
data["height"] = position
|
|
225
|
-
data["duration"] = duration
|
|
226
|
-
data["timestamp"] = Date.currentTimeStamp
|
|
227
|
-
data["target"] = tag
|
|
209
|
+
let progress = min(height / self.keyboardHeight, 1.0)
|
|
228
210
|
|
|
229
211
|
onCancelAnimation()
|
|
230
|
-
onEvent("onKeyboardMoveEnd",
|
|
231
|
-
onNotify("KeyboardController::keyboardDidShow",
|
|
212
|
+
onEvent("onKeyboardMoveEnd", height as NSNumber, progress as NSNumber, duration as NSNumber, tag)
|
|
213
|
+
onNotify("KeyboardController::keyboardDidShow", getEventParams(height, duration))
|
|
232
214
|
|
|
233
215
|
removeKeyboardWatcher()
|
|
234
216
|
setupKVObserver()
|
|
@@ -237,19 +219,12 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
237
219
|
}
|
|
238
220
|
|
|
239
221
|
@objc func keyboardDidDisappear(_ notification: Notification) {
|
|
240
|
-
let duration =
|
|
241
|
-
(notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double ?? 0) * 1000
|
|
242
|
-
)
|
|
222
|
+
let (duration, _) = metaDataFromNotification(notification)
|
|
243
223
|
tag = UIResponder.current.reactViewTag
|
|
244
|
-
var data = [AnyHashable: Any]()
|
|
245
|
-
data["height"] = 0
|
|
246
|
-
data["duration"] = duration
|
|
247
|
-
data["timestamp"] = Date.currentTimeStamp
|
|
248
|
-
data["target"] = tag
|
|
249
224
|
|
|
250
225
|
onCancelAnimation()
|
|
251
226
|
onEvent("onKeyboardMoveEnd", 0 as NSNumber, 0, duration as NSNumber, tag)
|
|
252
|
-
onNotify("KeyboardController::keyboardDidHide",
|
|
227
|
+
onNotify("KeyboardController::keyboardDidHide", getEventParams(0, duration))
|
|
253
228
|
|
|
254
229
|
removeKeyboardWatcher()
|
|
255
230
|
animation = nil
|
|
@@ -331,4 +306,23 @@ public class KeyboardMovementObserver: NSObject {
|
|
|
331
306
|
tag
|
|
332
307
|
)
|
|
333
308
|
}
|
|
309
|
+
|
|
310
|
+
private func metaDataFromNotification(_ notification: Notification) -> (Int, NSValue?) {
|
|
311
|
+
let duration = Int(
|
|
312
|
+
(notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double ?? 0) * 1000
|
|
313
|
+
)
|
|
314
|
+
let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
|
|
315
|
+
|
|
316
|
+
return (duration, keyboardFrame)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private func getEventParams(_ height: Double, _ duration: Int) -> [AnyHashable: Any] {
|
|
320
|
+
var data = [AnyHashable: Any]()
|
|
321
|
+
data["height"] = height
|
|
322
|
+
data["duration"] = duration
|
|
323
|
+
data["timestamp"] = Date.currentTimeStamp
|
|
324
|
+
data["target"] = tag
|
|
325
|
+
|
|
326
|
+
return data
|
|
327
|
+
}
|
|
334
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.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",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@commitlint/config-conventional": "^11.0.0",
|
|
74
|
-
"@react-native/eslint-config": "^0.75.
|
|
74
|
+
"@react-native/eslint-config": "^0.75.2",
|
|
75
75
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
76
76
|
"@testing-library/react-hooks": "^8.0.1",
|
|
77
77
|
"@types/jest": "^29.2.1",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"pod-install": "^0.1.0",
|
|
95
95
|
"prettier": "^2.8.8",
|
|
96
96
|
"react": "18.3.1",
|
|
97
|
-
"react-native": "0.75.
|
|
97
|
+
"react-native": "0.75.2",
|
|
98
98
|
"react-native-builder-bob": "^0.18.0",
|
|
99
99
|
"react-native-reanimated": "3.15.0",
|
|
100
100
|
"react-test-renderer": "18.2.0",
|