react-native-keyboard-controller 1.16.3 → 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.
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.16.3",
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",