react-native-keyboard-controller 1.5.7 → 1.5.8

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.
@@ -145,12 +145,14 @@ class KeyboardAnimationCallback(
145
145
  super.onEnd(animation)
146
146
 
147
147
  isTransitioning = false
148
+
149
+ var keyboardHeight = this.persistentKeyboardHeight
148
150
  // if keyboard becomes shown after interactive animation completion
149
151
  // getCurrentKeyboardHeight() will be `0` and isKeyboardVisible will be `false`
150
152
  // it's not correct behavior, so we are handling it here
151
153
  val isKeyboardShown = InteractiveKeyboardProvider.shown
152
154
  if (!isKeyboardShown) {
153
- this.persistentKeyboardHeight = getCurrentKeyboardHeight()
155
+ keyboardHeight = getCurrentKeyboardHeight()
154
156
  } else {
155
157
  // if keyboard is shown after interactions and the animation has finished
156
158
  // then we need to reset the state
@@ -158,8 +160,8 @@ class KeyboardAnimationCallback(
158
160
  }
159
161
  isKeyboardVisible = isKeyboardVisible || isKeyboardShown
160
162
 
161
- this.emitEvent("KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", getEventParams(this.persistentKeyboardHeight))
162
- this.sendEventToJS(KeyboardTransitionEvent(view.id, "topKeyboardMoveEnd", this.persistentKeyboardHeight, if (!isKeyboardVisible) 0.0 else 1.0))
163
+ this.emitEvent("KeyboardController::" + if (!isKeyboardVisible) "keyboardDidHide" else "keyboardDidShow", getEventParams(keyboardHeight))
164
+ this.sendEventToJS(KeyboardTransitionEvent(view.id, "topKeyboardMoveEnd", keyboardHeight, if (!isKeyboardVisible) 0.0 else 1.0))
163
165
  }
164
166
 
165
167
  private fun isKeyboardVisible(): Boolean {
@@ -284,8 +284,14 @@ internal class KeyboardAnimationController {
284
284
  velocityY = velocityY,
285
285
  )
286
286
  // The current inset matches either the shown/hidden inset, finish() immediately
287
- current == shown -> controller.finish(true)
288
- current == hidden -> controller.finish(false)
287
+ current == shown -> {
288
+ InteractiveKeyboardProvider.shown = true
289
+ controller.finish(true)
290
+ }
291
+ current == hidden -> {
292
+ InteractiveKeyboardProvider.shown = false
293
+ controller.finish(false)
294
+ }
289
295
  else -> {
290
296
  // Otherwise, we'll look at the current position...
291
297
  if (controller.currentFraction >= SCROLL_THRESHOLD) {
@@ -31,6 +31,7 @@ class KeyboardGestureAreaReactViewGroup(private val reactContext: ThemedReactCon
31
31
  private var lastTouchX = 0f
32
32
  private var lastTouchY = 0f
33
33
  private var lastWindowY = 0
34
+ private var keyboardHeight = 0
34
35
 
35
36
  // react props
36
37
  private var interpolator: Interpolator = LinearInterpolator()
@@ -87,6 +88,9 @@ class KeyboardGestureAreaReactViewGroup(private val reactContext: ThemedReactCon
87
88
 
88
89
  if (isHandling) {
89
90
  if (controller.isInsetAnimationInProgress()) {
91
+ if (keyboardHeight == 0) {
92
+ this.keyboardHeight = controller.getCurrentKeyboardHeight()
93
+ }
90
94
  // If we currently have control, we can update the IME insets to 'scroll'
91
95
  // the IME in
92
96
  val moveBy = this.interpolator.interpolate(dy.roundToInt(), this.getWindowHeight() - event.rawY.toInt(), controller.getCurrentKeyboardHeight())
@@ -122,10 +126,18 @@ class KeyboardGestureAreaReactViewGroup(private val reactContext: ThemedReactCon
122
126
  // Calculate the current velocityY, over 500 milliseconds
123
127
  velocityTracker?.computeCurrentVelocity(500)
124
128
  val velocityY = velocityTracker?.yVelocity
129
+ val isKeyboardPositionChanged =
130
+ // check `isInsetAnimationInProgress()` before, since direct usage of `getCurrentKeyboardHeight()`
131
+ // may throw exception
132
+ !controller.isInsetAnimationInProgress() ||
133
+ this.keyboardHeight != controller.getCurrentKeyboardHeight()
134
+ // if keyboard height was changed after finger movement -> we need to calculate final position
135
+ // and make an animated transition
136
+ val passedVelocityY = if (isKeyboardPositionChanged) velocityY else null
125
137
 
126
138
  // If we received a ACTION_UP event, end any current WindowInsetsAnimation passing
127
139
  // in the calculated Y velocity
128
- controller.animateToFinish(velocityY)
140
+ controller.animateToFinish(passedVelocityY)
129
141
 
130
142
  // Reset our touch handling state
131
143
  reset()
@@ -162,6 +174,7 @@ class KeyboardGestureAreaReactViewGroup(private val reactContext: ThemedReactCon
162
174
  lastTouchX = 0f
163
175
  lastTouchY = 0f
164
176
  lastWindowY = 0
177
+ keyboardHeight = 0
165
178
  bounds.setEmpty()
166
179
 
167
180
  velocityTracker?.recycle()
@@ -100,6 +100,11 @@ public class KeyboardMovementObserver: NSObject {
100
100
  if displayLink != nil {
101
101
  return
102
102
  }
103
+ // if keyboard height is not equal to its bounds - we can ignore
104
+ // values, since they'll be invalid and will cause UI jumps
105
+ if keyboardView?.bounds.size.height != keyboardHeight {
106
+ return
107
+ }
103
108
 
104
109
  // swiftlint:disable:next force_cast
105
110
  let keyboardFrameY = (change?[.newKey] as! NSValue).cgPointValue.y
@@ -208,7 +213,7 @@ public class KeyboardMovementObserver: NSObject {
208
213
  if subview.description.hasPrefix("<UIInputSetContainerView") {
209
214
  for hostView in subview.subviews {
210
215
  if hostView.description.hasPrefix("<UIInputSetHostView") {
211
- result = hostView as? UIView
216
+ result = hostView
212
217
  break
213
218
  }
214
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-keyboard-controller",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
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",