react-native-keyboard-controller 1.9.3 → 1.9.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.
package/README.md
CHANGED
|
@@ -22,10 +22,10 @@ Keyboard manager which works in identical way on both iOS and Android.
|
|
|
22
22
|
|
|
23
23
|
Install `react-native-keyboard-controller` package from npm:
|
|
24
24
|
|
|
25
|
-
```
|
|
25
|
+
```shell
|
|
26
26
|
yarn add react-native-keyboard-controller
|
|
27
27
|
# or
|
|
28
|
-
|
|
28
|
+
npm install react-native-keyboard-controller --save
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Documentation
|
|
@@ -41,6 +41,7 @@ class KeyboardAnimationCallback(
|
|
|
41
41
|
private var isTransitioning = false
|
|
42
42
|
private var duration = 0
|
|
43
43
|
private var viewTagFocused = -1
|
|
44
|
+
private var animation: ValueAnimator? = null
|
|
44
45
|
|
|
45
46
|
// listeners
|
|
46
47
|
private val focusListener = OnGlobalFocusChangeListener { oldFocus, newFocus ->
|
|
@@ -104,10 +105,6 @@ class KeyboardAnimationCallback(
|
|
|
104
105
|
* behavior should be consistent across all versions of platform. To level the difference we
|
|
105
106
|
* have to implement `onApplyWindowInsets` listener and simulate onStart/onProgress/onEnd
|
|
106
107
|
* events when keyboard changes its size.
|
|
107
|
-
* In the method below we fully recreate the logic that is implemented on old android versions:
|
|
108
|
-
* - we dispatch `keyboardWillShow` (onStart);
|
|
109
|
-
* - we dispatch change height/progress as animated values (onProgress);
|
|
110
|
-
* - we dispatch `keyboardDidShow` (onEnd).
|
|
111
108
|
*/
|
|
112
109
|
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {
|
|
113
110
|
val keyboardHeight = getCurrentKeyboardHeight()
|
|
@@ -133,57 +130,9 @@ class KeyboardAnimationCallback(
|
|
|
133
130
|
val isKeyboardSizeEqual = this.persistentKeyboardHeight == keyboardHeight
|
|
134
131
|
|
|
135
132
|
if (isKeyboardFullyVisible && !isKeyboardSizeEqual && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
133
|
+
Log.i(TAG, "onApplyWindowInsets: ${this.persistentKeyboardHeight} -> $keyboardHeight")
|
|
136
134
|
layoutObserver?.syncUpLayout()
|
|
137
|
-
this.
|
|
138
|
-
context.dispatchEvent(
|
|
139
|
-
view.id,
|
|
140
|
-
KeyboardTransitionEvent(
|
|
141
|
-
surfaceId,
|
|
142
|
-
view.id,
|
|
143
|
-
"topKeyboardMoveStart",
|
|
144
|
-
keyboardHeight,
|
|
145
|
-
1.0,
|
|
146
|
-
DEFAULT_ANIMATION_TIME,
|
|
147
|
-
viewTagFocused,
|
|
148
|
-
),
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
val animation =
|
|
152
|
-
ValueAnimator.ofFloat(this.persistentKeyboardHeight.toFloat(), keyboardHeight.toFloat())
|
|
153
|
-
animation.addUpdateListener { animator ->
|
|
154
|
-
val toValue = animator.animatedValue as Float
|
|
155
|
-
context.dispatchEvent(
|
|
156
|
-
view.id,
|
|
157
|
-
KeyboardTransitionEvent(
|
|
158
|
-
surfaceId,
|
|
159
|
-
view.id,
|
|
160
|
-
"topKeyboardMove",
|
|
161
|
-
toValue.toDouble(),
|
|
162
|
-
toValue.toDouble() / keyboardHeight,
|
|
163
|
-
DEFAULT_ANIMATION_TIME,
|
|
164
|
-
viewTagFocused,
|
|
165
|
-
),
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
animation.doOnEnd {
|
|
169
|
-
this.emitEvent("KeyboardController::keyboardDidShow", getEventParams(keyboardHeight))
|
|
170
|
-
context.dispatchEvent(
|
|
171
|
-
view.id,
|
|
172
|
-
KeyboardTransitionEvent(
|
|
173
|
-
surfaceId,
|
|
174
|
-
view.id,
|
|
175
|
-
"topKeyboardMoveEnd",
|
|
176
|
-
keyboardHeight,
|
|
177
|
-
1.0,
|
|
178
|
-
DEFAULT_ANIMATION_TIME,
|
|
179
|
-
viewTagFocused,
|
|
180
|
-
),
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
animation.setDuration(DEFAULT_ANIMATION_TIME.toLong()).startDelay = 0
|
|
184
|
-
animation.start()
|
|
185
|
-
|
|
186
|
-
this.persistentKeyboardHeight = keyboardHeight
|
|
135
|
+
this.onKeyboardResized(keyboardHeight)
|
|
187
136
|
}
|
|
188
137
|
|
|
189
138
|
return insets
|
|
@@ -320,6 +269,78 @@ class KeyboardAnimationCallback(
|
|
|
320
269
|
layoutObserver?.destroy()
|
|
321
270
|
}
|
|
322
271
|
|
|
272
|
+
/*
|
|
273
|
+
* In the method below we recreate the logic that used when keyboard appear/disappear:
|
|
274
|
+
* - we dispatch `keyboardWillShow` (onStart);
|
|
275
|
+
* - we dispatch change height/progress as animated values (onProgress);
|
|
276
|
+
* - we dispatch `keyboardDidShow` (onEnd).
|
|
277
|
+
*/
|
|
278
|
+
private fun onKeyboardResized(keyboardHeight: Double) {
|
|
279
|
+
if (this.animation?.isRunning == true) {
|
|
280
|
+
Log.i(TAG, "onKeyboardResized -> cancelling animation that is in progress")
|
|
281
|
+
// if animation is in progress, then we are:
|
|
282
|
+
// - removing listeners (update, onEnd)
|
|
283
|
+
// - updating `persistentKeyboardHeight` to latest animated value
|
|
284
|
+
// - cancelling animation to free up CPU resources
|
|
285
|
+
this.animation?.removeAllListeners()
|
|
286
|
+
this.persistentKeyboardHeight = (this.animation?.animatedValue as Float).toDouble()
|
|
287
|
+
this.animation?.cancel()
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
this.emitEvent("KeyboardController::keyboardWillShow", getEventParams(keyboardHeight))
|
|
291
|
+
context.dispatchEvent(
|
|
292
|
+
view.id,
|
|
293
|
+
KeyboardTransitionEvent(
|
|
294
|
+
surfaceId,
|
|
295
|
+
view.id,
|
|
296
|
+
"topKeyboardMoveStart",
|
|
297
|
+
keyboardHeight,
|
|
298
|
+
1.0,
|
|
299
|
+
DEFAULT_ANIMATION_TIME,
|
|
300
|
+
viewTagFocused,
|
|
301
|
+
),
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
val animation =
|
|
305
|
+
ValueAnimator.ofFloat(this.persistentKeyboardHeight.toFloat(), keyboardHeight.toFloat())
|
|
306
|
+
animation.addUpdateListener { animator ->
|
|
307
|
+
val toValue = animator.animatedValue as Float
|
|
308
|
+
context.dispatchEvent(
|
|
309
|
+
view.id,
|
|
310
|
+
KeyboardTransitionEvent(
|
|
311
|
+
surfaceId,
|
|
312
|
+
view.id,
|
|
313
|
+
"topKeyboardMove",
|
|
314
|
+
toValue.toDouble(),
|
|
315
|
+
toValue.toDouble() / keyboardHeight,
|
|
316
|
+
DEFAULT_ANIMATION_TIME,
|
|
317
|
+
viewTagFocused,
|
|
318
|
+
),
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
animation.doOnEnd {
|
|
322
|
+
this.emitEvent("KeyboardController::keyboardDidShow", getEventParams(keyboardHeight))
|
|
323
|
+
context.dispatchEvent(
|
|
324
|
+
view.id,
|
|
325
|
+
KeyboardTransitionEvent(
|
|
326
|
+
surfaceId,
|
|
327
|
+
view.id,
|
|
328
|
+
"topKeyboardMoveEnd",
|
|
329
|
+
keyboardHeight,
|
|
330
|
+
1.0,
|
|
331
|
+
DEFAULT_ANIMATION_TIME,
|
|
332
|
+
viewTagFocused,
|
|
333
|
+
),
|
|
334
|
+
)
|
|
335
|
+
this.animation = null
|
|
336
|
+
}
|
|
337
|
+
animation.setDuration(DEFAULT_ANIMATION_TIME.toLong()).startDelay = 0
|
|
338
|
+
animation.start()
|
|
339
|
+
|
|
340
|
+
this.animation = animation
|
|
341
|
+
this.persistentKeyboardHeight = keyboardHeight
|
|
342
|
+
}
|
|
343
|
+
|
|
323
344
|
private fun isKeyboardVisible(): Boolean {
|
|
324
345
|
val insets = ViewCompat.getRootWindowInsets(view)
|
|
325
346
|
|
package/package.json
CHANGED