react-native-keyboard-controller 1.16.2 → 1.16.4

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.
@@ -70,6 +70,12 @@ android {
70
70
  } else {
71
71
  java.srcDirs += ['src/paper']
72
72
  }
73
+
74
+ if (project.ext.shouldUseBaseReactPackage()) {
75
+ java.srcDirs += ['src/base']
76
+ } else {
77
+ java.srcDirs += ['src/turbo']
78
+ }
73
79
  }
74
80
  }
75
81
 
@@ -39,4 +39,8 @@ project.ext.resolveReactNativeDirectory = { ->
39
39
 
40
40
  project.ext.shouldConsumeReactNativeFromMavenCentral = { ->
41
41
  return REACT_NATIVE_MINOR_VERSION >= 71
42
- }
42
+ }
43
+
44
+ project.ext.shouldUseBaseReactPackage = { ->
45
+ return REACT_NATIVE_MINOR_VERSION >= 74
46
+ }
@@ -0,0 +1,61 @@
1
+ package com.reactnativekeyboardcontroller
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import com.facebook.react.uimanager.ViewManager
9
+ import com.reactnativekeyboardcontroller.modules.KeyboardControllerModuleImpl
10
+ import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImpl
11
+
12
+ class KeyboardControllerPackage : BaseReactPackage() {
13
+ override fun getModule(
14
+ name: String,
15
+ reactContext: ReactApplicationContext,
16
+ ): NativeModule? =
17
+ when (name) {
18
+ KeyboardControllerModuleImpl.NAME -> {
19
+ KeyboardControllerModule(reactContext)
20
+ }
21
+ StatusBarManagerCompatModuleImpl.NAME -> {
22
+ StatusBarManagerCompatModule(reactContext)
23
+ }
24
+ else -> {
25
+ null
26
+ }
27
+ }
28
+
29
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
30
+ ReactModuleInfoProvider {
31
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
32
+ val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
33
+
34
+ moduleInfos[KeyboardControllerModuleImpl.NAME] =
35
+ ReactModuleInfo(
36
+ KeyboardControllerModuleImpl.NAME,
37
+ KeyboardControllerModuleImpl.NAME,
38
+ false, // canOverrideExistingModule
39
+ false, // needsEagerInit
40
+ false, // isCxxModule
41
+ isTurboModule, // isTurboModule
42
+ )
43
+ moduleInfos[StatusBarManagerCompatModuleImpl.NAME] =
44
+ ReactModuleInfo(
45
+ StatusBarManagerCompatModuleImpl.NAME,
46
+ StatusBarManagerCompatModuleImpl.NAME,
47
+ false, // canOverrideExistingModule
48
+ false, // needsEagerInit
49
+ false, // isCxxModule
50
+ isTurboModule, // isTurboModule
51
+ )
52
+ moduleInfos
53
+ }
54
+
55
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
56
+ listOf(
57
+ KeyboardControllerViewManager(reactContext),
58
+ KeyboardGestureAreaViewManager(reactContext),
59
+ OverKeyboardViewManager(reactContext),
60
+ )
61
+ }
@@ -1,6 +1,5 @@
1
1
  package com.reactnativekeyboardcontroller.interactive
2
2
 
3
3
  object InteractiveKeyboardProvider {
4
- var shown = false
5
4
  var isInteractive = false
6
5
  }
@@ -233,22 +233,18 @@ internal class KeyboardAnimationController {
233
233
  when (current) {
234
234
  // The current inset matches either the shown/hidden inset, finish() immediately
235
235
  shown -> {
236
- InteractiveKeyboardProvider.shown = true
237
236
  controller.finish(true)
238
237
  }
239
238
  hidden -> {
240
- InteractiveKeyboardProvider.shown = false
241
239
  controller.finish(false)
242
240
  }
243
241
  else -> {
244
242
  // Otherwise, we'll look at the current position...
245
243
  if (controller.currentFraction >= SCROLL_THRESHOLD) {
246
244
  // If the IME is past the 'threshold' we snap to the toggled state
247
- InteractiveKeyboardProvider.shown = !isImeShownAtStart
248
245
  controller.finish(!isImeShownAtStart)
249
246
  } else {
250
247
  // ...otherwise, we snap back to the original visibility
251
- InteractiveKeyboardProvider.shown = isImeShownAtStart
252
248
  controller.finish(isImeShownAtStart)
253
249
  }
254
250
  }
@@ -287,11 +283,9 @@ internal class KeyboardAnimationController {
287
283
  )
288
284
  // The current inset matches either the shown/hidden inset, finish() immediately
289
285
  current == shown -> {
290
- InteractiveKeyboardProvider.shown = true
291
286
  controller.finish(true)
292
287
  }
293
288
  current == hidden -> {
294
- InteractiveKeyboardProvider.shown = false
295
289
  controller.finish(false)
296
290
  }
297
291
  else -> {
@@ -101,7 +101,14 @@ class FocusedInputObserver(
101
101
  // unfocused or focus was changed
102
102
  if (newFocus == null || oldFocus != null) {
103
103
  lastFocusedInput?.removeOnLayoutChangeListener(layoutListener)
104
- lastFocusedInput?.removeTextChangedListener(textWatcher)
104
+ lastFocusedInput?.let { input ->
105
+ val watcher = textWatcher
106
+ // remove it asynchronously to avoid crash in stripe input
107
+ // see https://github.com/stripe/stripe-android/issues/10178
108
+ input.post {
109
+ input.removeTextChangedListener(watcher)
110
+ }
111
+ }
105
112
  selectionSubscription?.invoke()
106
113
  lastFocusedInput = null
107
114
  }
@@ -33,7 +33,7 @@ data class KeyboardAnimationCallbackConfig(
33
33
  val persistentInsetTypes: Int,
34
34
  val deferredInsetTypes: Int,
35
35
  val dispatchMode: Int = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP,
36
- val hasTranslucentNavigationBar: Boolean = false,
36
+ var hasTranslucentNavigationBar: Boolean,
37
37
  )
38
38
 
39
39
  interface Suspendable {
@@ -62,6 +62,8 @@ class KeyboardAnimationCallback(
62
62
  private var duration = 0
63
63
  private var viewTagFocused = -1
64
64
  private var animationsToSkip = hashSetOf<WindowInsetsAnimationCompat>()
65
+ private val isKeyboardInteractive: Boolean
66
+ get() = duration == -1
65
67
  override var isSuspended: Boolean = false
66
68
 
67
69
  // listeners
@@ -293,46 +295,47 @@ class KeyboardAnimationCallback(
293
295
  isTransitioning = false
294
296
  duration = animation.durationMillis.toInt()
295
297
 
296
- var keyboardHeight = this.persistentKeyboardHeight
297
- // if keyboard becomes shown after interactive animation completion
298
- // getCurrentKeyboardHeight() will be `0` and isKeyboardVisible will be `false`
299
- // it's not correct behavior, so we are handling it here
300
- val isKeyboardShown = InteractiveKeyboardProvider.shown
301
- if (!isKeyboardShown) {
302
- keyboardHeight = getCurrentKeyboardHeight()
303
- } else {
304
- // if keyboard is shown after interactions and the animation has finished
305
- // then we need to reset the state
306
- InteractiveKeyboardProvider.shown = false
307
- }
308
- isKeyboardVisible = isKeyboardVisible || isKeyboardShown
309
- prevKeyboardHeight = keyboardHeight
298
+ val runnable =
299
+ Runnable {
300
+ val keyboardHeight = getCurrentKeyboardHeight()
310
301
 
311
- if (animation in animationsToSkip) {
312
- duration = 0
313
- animationsToSkip.remove(animation)
314
- return
315
- }
302
+ isKeyboardVisible = isKeyboardVisible()
303
+ prevKeyboardHeight = keyboardHeight
316
304
 
317
- context.emitEvent(
318
- "KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow",
319
- getEventParams(keyboardHeight),
320
- )
321
- context.dispatchEvent(
322
- eventPropagationView.id,
323
- KeyboardTransitionEvent(
324
- surfaceId,
325
- eventPropagationView.id,
326
- KeyboardTransitionEvent.End,
327
- keyboardHeight,
328
- if (!isKeyboardVisible) 0.0 else 1.0,
329
- duration,
330
- viewTagFocused,
331
- ),
332
- )
305
+ if (animation in animationsToSkip) {
306
+ duration = 0
307
+ animationsToSkip.remove(animation)
308
+ return@Runnable
309
+ }
333
310
 
334
- // reset to initial state
335
- duration = 0
311
+ context.emitEvent(
312
+ "KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow",
313
+ getEventParams(keyboardHeight),
314
+ )
315
+ context.dispatchEvent(
316
+ eventPropagationView.id,
317
+ KeyboardTransitionEvent(
318
+ surfaceId,
319
+ eventPropagationView.id,
320
+ KeyboardTransitionEvent.End,
321
+ keyboardHeight,
322
+ if (!isKeyboardVisible) 0.0 else 1.0,
323
+ duration,
324
+ viewTagFocused,
325
+ ),
326
+ )
327
+
328
+ // reset to initial state
329
+ duration = 0
330
+ }
331
+
332
+ if (isKeyboardInteractive) {
333
+ // in case of interactive keyboard we can not read keyboard frame straight away
334
+ // (because we'll always read `0`), so we are posting runnable to the main thread
335
+ view.post(runnable)
336
+ } else {
337
+ runnable.run()
338
+ }
336
339
  }
337
340
 
338
341
  fun syncKeyboardPosition(
@@ -23,15 +23,15 @@ private val areEventsComingFromOwnWindow = !Keyboard.IS_ANIMATION_EMULATED
23
23
  class ModalAttachedWatcher(
24
24
  private val view: ReactViewGroup,
25
25
  private val reactContext: ThemedReactContext,
26
- private val config: () -> KeyboardAnimationCallbackConfig,
26
+ private val config: KeyboardAnimationCallbackConfig,
27
27
  private var callback: () -> KeyboardAnimationCallback?,
28
28
  ) : EventDispatcherListener {
29
29
  private val archType = if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) UIManagerType.FABRIC else UIManagerType.DEFAULT
30
30
  private val uiManager = UIManagerHelper.getUIManager(reactContext.reactApplicationContext, archType)
31
31
  private val eventDispatcher = UIManagerHelper.getEventDispatcher(reactContext.reactApplicationContext, archType)
32
32
 
33
- override fun onEventDispatch(event: Event<out Event<*>>?) {
34
- if (event?.eventName != MODAL_SHOW_EVENT) {
33
+ override fun onEventDispatch(event: Event<*>) {
34
+ if (event.eventName != MODAL_SHOW_EVENT) {
35
35
  return
36
36
  }
37
37
 
@@ -61,7 +61,7 @@ class ModalAttachedWatcher(
61
61
  view = rootView,
62
62
  eventPropagationView = view,
63
63
  context = reactContext,
64
- config = config(),
64
+ config = config,
65
65
  )
66
66
 
67
67
  rootView.addView(eventView)
@@ -39,17 +39,16 @@ class EdgeToEdgeReactViewGroup(
39
39
  private var eventView: ReactViewGroup? = null
40
40
  private var wasMounted = false
41
41
  private var callback: KeyboardAnimationCallback? = null
42
- private val config: KeyboardAnimationCallbackConfig
43
- get() =
44
- KeyboardAnimationCallbackConfig(
45
- persistentInsetTypes = WindowInsetsCompat.Type.systemBars(),
46
- deferredInsetTypes = WindowInsetsCompat.Type.ime(),
47
- dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
48
- hasTranslucentNavigationBar = isNavigationBarTranslucent,
49
- )
42
+ private val config =
43
+ KeyboardAnimationCallbackConfig(
44
+ persistentInsetTypes = WindowInsetsCompat.Type.systemBars(),
45
+ deferredInsetTypes = WindowInsetsCompat.Type.ime(),
46
+ dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
47
+ hasTranslucentNavigationBar = isNavigationBarTranslucent,
48
+ )
50
49
 
51
50
  // managers/watchers
52
- private val modalAttachedWatcher = ModalAttachedWatcher(this, reactContext, ::config, ::getKeyboardCallback)
51
+ private val modalAttachedWatcher = ModalAttachedWatcher(this, reactContext, config, ::getKeyboardCallback)
53
52
 
54
53
  init {
55
54
  reactContext.setupWindowDimensionsListener()
@@ -212,6 +211,7 @@ class EdgeToEdgeReactViewGroup(
212
211
 
213
212
  fun setNavigationBarTranslucent(isNavigationBarTranslucent: Boolean) {
214
213
  this.isNavigationBarTranslucent = isNavigationBarTranslucent
214
+ this.config.hasTranslucentNavigationBar = isNavigationBarTranslucent
215
215
  }
216
216
 
217
217
  fun setPreserveEdgeToEdge(isPreservingEdgeToEdge: Boolean) {
@@ -163,7 +163,7 @@ class OverKeyboardRootViewGroup(
163
163
 
164
164
  // region RootView methods
165
165
  override fun onChildStartedNativeGesture(
166
- childView: View,
166
+ childView: View?,
167
167
  ev: MotionEvent,
168
168
  ) {
169
169
  eventDispatcher?.let { eventDispatcher ->
@@ -12,7 +12,7 @@ interface RootViewCompat : RootView {
12
12
  "This method shouldn't be used anymore.",
13
13
  ReplaceWith("onChildStartedNativeGesture(View childView, MotionEvent ev)"),
14
14
  )
15
- override fun onChildStartedNativeGesture(ev: MotionEvent?) {
15
+ override fun onChildStartedNativeGesture(ev: MotionEvent) {
16
16
  onChildStartedNativeGesture(null, ev)
17
17
  }
18
18
  }
@@ -80,12 +80,6 @@ public class FocusedInputObserver: NSObject {
80
80
  name: UIResponder.keyboardWillShowNotification,
81
81
  object: nil
82
82
  )
83
- NotificationCenter.default.addObserver(
84
- self,
85
- selector: #selector(keyboardWillHide),
86
- name: UIResponder.keyboardWillHideNotification,
87
- object: nil
88
- )
89
83
  NotificationCenter.default.addObserver(
90
84
  self,
91
85
  selector: #selector(didReceiveFocus),
@@ -118,10 +112,6 @@ public class FocusedInputObserver: NSObject {
118
112
  NotificationCenter.default.removeObserver(self)
119
113
  }
120
114
 
121
- @objc func keyboardWillHide(_: Notification) {
122
- onBlur()
123
- }
124
-
125
115
  @objc func didReceiveFocus(_: Notification) {
126
116
  if UIResponder.current == currentResponder {
127
117
  // focus was already handled by keyboard event
@@ -131,22 +121,13 @@ public class FocusedInputObserver: NSObject {
131
121
  onFocus()
132
122
  }
133
123
 
134
- /**
135
- * We handle blur events in `keyboardWillHide` handler
136
- * And this additional handler is needed only to have
137
- * a consistent state when keyboard is not shown
138
- */
139
124
  @objc func didReceiveBlur(_: Notification) {
140
- if currentResponder == nil {
141
- // blur was already handled by keyboard event
142
- return
143
- }
144
125
  // blur gets triggered on endEditing, so we check if no upcoming
145
126
  // didReceiveFocus events are coming to exclude `noFocusedInput`
146
127
  // event when user switches between inputs
147
128
  DispatchQueue.main.async {
148
129
  // check that it wasn't a switch between inputs
149
- if self.currentResponder == nil {
130
+ if !(UIResponder.current is TextInput) {
150
131
  self.onBlur()
151
132
  }
152
133
  }
@@ -173,10 +154,6 @@ public class FocusedInputObserver: NSObject {
173
154
  }
174
155
 
175
156
  func onBlur() {
176
- // when we switch to next input, but `showSoftInput={false}`
177
- if UIResponder.current is TextInput {
178
- return
179
- }
180
157
  removeObservers(newResponder: nil)
181
158
  currentInput = nil
182
159
  currentResponder = nil
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.16.2",
3
+ "version": "1.16.4",
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",
@@ -80,11 +80,11 @@
80
80
  },
81
81
  "devDependencies": {
82
82
  "@commitlint/config-conventional": "^11.0.0",
83
- "@react-native/babel-preset": "0.76.2",
84
- "@react-native/eslint-config": "0.76.2",
83
+ "@react-native/babel-preset": "0.77.0",
84
+ "@react-native/eslint-config": "0.77.0",
85
85
  "@release-it/conventional-changelog": "^2.0.0",
86
86
  "@testing-library/react-hooks": "^8.0.1",
87
- "@types/jest": "^29.2.1",
87
+ "@types/jest": "^29.5.13",
88
88
  "@types/react": "^18.2.6",
89
89
  "@typescript-eslint/eslint-plugin": "^6.7.4",
90
90
  "@typescript-eslint/parser": "^6.7.4",
@@ -105,9 +105,9 @@
105
105
  "pod-install": "^0.1.0",
106
106
  "prettier": "^2.8.8",
107
107
  "react": "18.3.1",
108
- "react-native": "0.76.2",
108
+ "react-native": "0.77.0",
109
109
  "react-native-builder-bob": "^0.18.0",
110
- "react-native-reanimated": "3.16.1",
110
+ "react-native-reanimated": "3.16.7",
111
111
  "react-test-renderer": "18.2.0",
112
112
  "release-it": "^14.2.2",
113
113
  "typescript": "5.6.3"
@@ -170,6 +170,13 @@
170
170
  "jsSrcsDir": "./src/specs",
171
171
  "android": {
172
172
  "javaPackageName": "com.reactnativekeyboardcontroller"
173
+ },
174
+ "ios": {
175
+ "componentProvider": {
176
+ "KeyboardControllerView": "KeyboardControllerView",
177
+ "KeyboardGestureArea": "KeyboardGestureArea",
178
+ "OverKeyboardView": "OverKeyboardView"
179
+ }
173
180
  }
174
181
  }
175
182
  }