react-native-keyboard-controller 1.13.0 → 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.
@@ -1,6 +1,7 @@
1
1
  package com.reactnativekeyboardcontroller.views
2
2
 
3
3
  import android.annotation.SuppressLint
4
+ import android.content.res.Configuration
4
5
  import android.os.Handler
5
6
  import android.os.Looper
6
7
  import android.util.Log
@@ -68,6 +69,10 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
68
69
 
69
70
  this.removeKeyboardCallbacks()
70
71
  }
72
+
73
+ override fun onConfigurationChanged(newConfig: Configuration?) {
74
+ this.reApplyWindowInsets()
75
+ }
71
76
  // endregion
72
77
 
73
78
  // region State manager helpers
@@ -83,25 +88,23 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
83
88
 
84
89
  val shouldApplyZeroPaddingTop = !active || this.isStatusBarTranslucent
85
90
  val shouldApplyZeroPaddingBottom = !active || this.isNavigationBarTranslucent
91
+ val navBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
92
+ val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
93
+
86
94
  params.setMargins(
87
- 0,
95
+ navBarInsets.left,
88
96
  if (shouldApplyZeroPaddingTop) {
89
97
  0
90
98
  } else {
91
- (
92
- insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.top
93
- ?: 0
94
- )
99
+ systemBarInsets.top
95
100
  },
96
- 0,
101
+ navBarInsets.right,
97
102
  if (shouldApplyZeroPaddingBottom) {
98
103
  0
99
104
  } else {
100
- insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom
101
- ?: 0
105
+ navBarInsets.bottom
102
106
  },
103
107
  )
104
-
105
108
  content?.layoutParams = params
106
109
 
107
110
  val defaultInsets = ViewCompat.onApplyWindowInsets(v, insets)
@@ -164,6 +167,11 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
164
167
  // for more details
165
168
  Handler(Looper.getMainLooper()).post { view.removeSelf() }
166
169
  }
170
+
171
+ private fun reApplyWindowInsets() {
172
+ this.setupWindowInsets()
173
+ this.requestApplyInsetsWhenAttached()
174
+ }
167
175
  // endregion
168
176
 
169
177
  // region State managers
@@ -206,8 +214,7 @@ class EdgeToEdgeReactViewGroup(private val reactContext: ThemedReactContext) : R
206
214
  fun forceStatusBarTranslucent(isStatusBarTranslucent: Boolean) {
207
215
  if (active && this.isStatusBarTranslucent != isStatusBarTranslucent) {
208
216
  this.isStatusBarTranslucent = isStatusBarTranslucent
209
- this.setupWindowInsets()
210
- this.requestApplyInsetsWhenAttached()
217
+ this.reApplyWindowInsets()
211
218
  }
212
219
  }
213
220
  // endregion
@@ -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
- if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
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", data)
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 = Int(
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", data)
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
- if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
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
- let duration = Int(
218
- (notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double ?? 0) * 1000
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(position / self.keyboardHeight, 1.0)
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", position as NSNumber, progress as NSNumber, duration as NSNumber, tag)
231
- onNotify("KeyboardController::keyboardDidShow", data)
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 = Int(
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", data)
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
  }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=event-handler.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["event-handler.d.ts"],"sourcesContent":["declare function registerEventHandler(\n handler: (event: never) => void,\n eventName: string,\n viewTag: number,\n): number;\ndeclare function unregisterEventHandler(id: number): void;\n\nexport { registerEventHandler, unregisterEventHandler };\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event-handler.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["event-handler.d.ts"],"sourcesContent":["declare function registerEventHandler(\n handler: (event: never) => void,\n eventName: string,\n viewTag: number,\n): number;\ndeclare function unregisterEventHandler(id: number): void;\n\nexport { registerEventHandler, unregisterEventHandler };\n"],"mappings":"","ignoreList":[]}
@@ -1,5 +1,6 @@
1
- export {};
2
- //# sourceMappingURL=event-handler.js.map-native-reanimated/src/core");
1
+ let REACore = null;
2
+ try {
3
+ REACore = require("react-native-reanimated/src/core");
3
4
  } catch (e1) {
4
5
  try {
5
6
  REACore = require("react-native-reanimated/src/reanimated2/core");
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["event-handler.ts"],"sourcesContent":["declare function registerEventHandler(\n handler: (event: never) => void,\n eventName: string,\n viewTag: number,\n): number;\ndeclare function unregisterEventHandler(id: number): void;\n\nexport { registerEventHandler, unregisterEventHandler };\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":["REACore","require","e1","e2","console","warn","registerEventHandler","unregisterEventHandler"],"sources":["event-handler.js"],"sourcesContent":["let REACore = null;\n\ntry {\n REACore = require(\"react-native-reanimated/src/core\");\n} catch (e1) {\n try {\n REACore = require(\"react-native-reanimated/src/reanimated2/core\");\n } catch (e2) {\n console.warn(\"Failed to load REACore from both paths\");\n }\n}\nconst registerEventHandler = REACore.registerEventHandler;\nconst unregisterEventHandler = REACore.unregisterEventHandler;\n\nexport { registerEventHandler, unregisterEventHandler };\n"],"mappings":"AAAA,IAAIA,OAAO,GAAG,IAAI;AAElB,IAAI;EACFA,OAAO,GAAGC,OAAO,CAAC,kCAAkC,CAAC;AACvD,CAAC,CAAC,OAAOC,EAAE,EAAE;EACX,IAAI;IACFF,OAAO,GAAGC,OAAO,CAAC,8CAA8C,CAAC;EACnE,CAAC,CAAC,OAAOE,EAAE,EAAE;IACXC,OAAO,CAACC,IAAI,CAAC,wCAAwC,CAAC;EACxD;AACF;AACA,MAAMC,oBAAoB,GAAGN,OAAO,CAACM,oBAAoB;AACzD,MAAMC,sBAAsB,GAAGP,OAAO,CAACO,sBAAsB;AAE7D,SAASD,oBAAoB,EAAEC,sBAAsB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.13.0",
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.0-rc.6",
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.0-rc.6",
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",
@@ -1,3 +0,0 @@
1
- declare function registerEventHandler(handler: (event: never) => void, eventName: string, viewTag: number): number;
2
- declare function unregisterEventHandler(id: number): void;
3
- export { registerEventHandler, unregisterEventHandler };
File without changes