Skip to content

Commit 78073c7

Browse files
committed
fix: make code organization slightly better
1 parent abfb5b7 commit 78073c7

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class KeyboardAnimationCallback(
5757
private val surfaceId = UIManagerHelper.getSurfaceId(eventPropagationView)
5858

5959
// state variables
60-
private var persistentKeyboardHeight = 0.0
61-
private var prevKeyboardHeight = 0.0
60+
private var persistentKeyboardHeight = getCurrentKeyboardHeight()
61+
private var prevKeyboardHeight = getCurrentKeyboardHeight()
6262
private var isKeyboardVisible = false
6363
private var isTransitioning = false
6464
private var duration = 0
@@ -68,13 +68,6 @@ class KeyboardAnimationCallback(
6868
get() = duration == -1
6969
override var isSuspended: Boolean = false
7070

71-
init {
72-
if (source != null) {
73-
this.persistentKeyboardHeight = source.persistentKeyboardHeight
74-
this.prevKeyboardHeight = source.prevKeyboardHeight
75-
}
76-
}
77-
7871
// listeners
7972
private val focusListener =
8073
OnGlobalFocusChangeListener { oldFocus, newFocus ->
@@ -179,7 +172,7 @@ class KeyboardAnimationCallback(
179172
if (prevKeyboardHeight != newHeight && !isMoving && !isSuspended) {
180173
Logger.w(
181174
TAG,
182-
"detected desynchronized state - force updating it. $prevKeyboardHeight -> $newHeight. Modal ${this.source}",
175+
"detected desynchronized state - force updating it. $prevKeyboardHeight -> $newHeight. Attached: ${view.isAttachedToWindow} EVA: ${this.eventPropagationView.isAttachedToWindow} Modal ${this.source}",
183176
)
184177
this.syncKeyboardPosition(newHeight, newHeight > 0)
185178
}
@@ -190,6 +183,8 @@ class KeyboardAnimationCallback(
190183
override fun onPrepare(animation: WindowInsetsAnimationCompat) {
191184
super.onPrepare(animation)
192185

186+
println("desynchronized - onPrepare")
187+
193188
if (!animation.isKeyboardAnimation || isSuspended) {
194189
return
195190
}

android/src/main/java/com/reactnativekeyboardcontroller/modal/ModalAttachedWatcher.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class ModalAttachedWatcher(
7777
// callback - otherwise keyboard transitions will not be animated
7878
cb.suspend(true)
7979
// attaching callback to Modal on Android < 12 can cause ghost animations, see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/718
80-
// and overall attaching additional callbacks (if animation events go through the main window) is not necessary
80+
// and overall attaching additional callbacks (if animation events go through the main window)
81+
// is not necessary
8182
ViewCompat.setWindowInsetsAnimationCallback(rootView, callback)
8283
ViewCompat.setOnApplyWindowInsetsListener(eventView, callback)
8384
}

0 commit comments

Comments
 (0)