react-native-keyboard-controller 1.4.2 → 1.4.3
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/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt +2 -2
- package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/View.kt +29 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardControllerViewManagerImpl.kt +6 -5
- package/package.json +1 -1
package/android/src/main/java/com/reactnativekeyboardcontroller/KeyboardAnimationCallback.kt
CHANGED
|
@@ -11,9 +11,9 @@ import androidx.core.view.ViewCompat
|
|
|
11
11
|
import androidx.core.view.WindowInsetsAnimationCompat
|
|
12
12
|
import androidx.core.view.WindowInsetsCompat
|
|
13
13
|
import com.facebook.react.bridge.Arguments
|
|
14
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
15
14
|
import com.facebook.react.bridge.WritableMap
|
|
16
15
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
16
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
17
17
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
18
18
|
import com.facebook.react.uimanager.events.Event
|
|
19
19
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
@@ -26,7 +26,7 @@ class KeyboardAnimationCallback(
|
|
|
26
26
|
val persistentInsetTypes: Int,
|
|
27
27
|
val deferredInsetTypes: Int,
|
|
28
28
|
dispatchMode: Int = DISPATCH_MODE_STOP,
|
|
29
|
-
val context:
|
|
29
|
+
val context: ThemedReactContext?,
|
|
30
30
|
val onApplyWindowInsetsListener: OnApplyWindowInsetsListener,
|
|
31
31
|
) : WindowInsetsAnimationCompat.Callback(dispatchMode), OnApplyWindowInsetsListener {
|
|
32
32
|
private val TAG = KeyboardAnimationCallback::class.qualifiedName
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.reactnativekeyboardcontroller.extensions
|
|
2
|
+
|
|
3
|
+
import android.os.Build
|
|
4
|
+
import android.view.View
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Call this everytime when using [ViewCompat.setOnApplyWindowInsetsListener]
|
|
8
|
+
* to ensure that insets are always received.
|
|
9
|
+
* @see https://stackoverflow.com/a/61909205/9272042
|
|
10
|
+
*/
|
|
11
|
+
fun View.requestApplyInsetsWhenAttached() {
|
|
12
|
+
// https://chris.banes.dev/2019/04/12/insets-listeners-to-layouts/
|
|
13
|
+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT && isAttachedToWindow) {
|
|
14
|
+
// We're already attached, just request as normal
|
|
15
|
+
requestApplyInsets()
|
|
16
|
+
} else {
|
|
17
|
+
// We're not attached to the hierarchy, add a listener to request when we are
|
|
18
|
+
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
19
|
+
override fun onViewAttachedToWindow(v: View) {
|
|
20
|
+
v.removeOnAttachStateChangeListener(this)
|
|
21
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
|
|
22
|
+
v.requestApplyInsets()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun onViewDetachedFromWindow(v: View) = Unit
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -11,16 +11,16 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
11
11
|
import com.facebook.react.views.view.ReactViewGroup
|
|
12
12
|
import com.reactnativekeyboardcontroller.KeyboardAnimationCallback
|
|
13
13
|
import com.reactnativekeyboardcontroller.R
|
|
14
|
+
import com.reactnativekeyboardcontroller.extensions.requestApplyInsetsWhenAttached
|
|
14
15
|
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
|
|
15
16
|
|
|
16
|
-
class KeyboardControllerViewManagerImpl(
|
|
17
|
+
class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicationContext) {
|
|
17
18
|
private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
|
|
18
|
-
private var mReactContext = reactContext
|
|
19
19
|
private var isStatusBarTranslucent = false
|
|
20
20
|
|
|
21
21
|
fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
|
|
22
22
|
val view = EdgeToEdgeReactViewGroup(reactContext)
|
|
23
|
-
val activity =
|
|
23
|
+
val activity = reactContext.currentActivity
|
|
24
24
|
|
|
25
25
|
if (activity == null) {
|
|
26
26
|
Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
|
|
@@ -34,10 +34,10 @@ class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
|
|
|
34
34
|
// We explicitly allow dispatch to continue down to binding.messageHolder's
|
|
35
35
|
// child views, so that step 2.5 below receives the call
|
|
36
36
|
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
|
|
37
|
-
context =
|
|
37
|
+
context = reactContext,
|
|
38
38
|
onApplyWindowInsetsListener = { v, insets ->
|
|
39
39
|
val content =
|
|
40
|
-
|
|
40
|
+
reactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
|
|
41
41
|
R.id.action_bar_root,
|
|
42
42
|
)
|
|
43
43
|
content?.setPadding(
|
|
@@ -52,6 +52,7 @@ class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
|
|
|
52
52
|
)
|
|
53
53
|
ViewCompat.setWindowInsetsAnimationCallback(view, callback)
|
|
54
54
|
ViewCompat.setOnApplyWindowInsetsListener(view, callback)
|
|
55
|
+
view.requestApplyInsetsWhenAttached()
|
|
55
56
|
|
|
56
57
|
return view
|
|
57
58
|
}
|
package/package.json
CHANGED