Skip to content

Commit 0cbada6

Browse files
authored
fix: create view using context provided by createViewInstance method (#114)
## 📜 Description Use context provided by `createViewInstance` for view creation. ## 💡 Motivation and Context Partially fixes the problem described in #113 We need to use actual context provided by `createViewInstance`. Otherwise after hot reloading context may be invalid and keyboard events will not be send to JS thread (since UIManager will be invalid). ## 📢 Changelog ### Android - use `reactContext` from params instead of constructor value; ## 🤔 How Has This Been Tested? Tested manually on Pixel 7 Pro and Xiaomi Redmi Note 5 Pro (real devices). ## 📝 Checklist - [x] CI successfully passed
1 parent 894c192 commit 0cbada6

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import androidx.core.view.ViewCompat
1111
import androidx.core.view.WindowInsetsAnimationCompat
1212
import androidx.core.view.WindowInsetsCompat
1313
import com.facebook.react.bridge.Arguments
14-
import com.facebook.react.bridge.ReactApplicationContext
1514
import com.facebook.react.bridge.WritableMap
1615
import com.facebook.react.modules.core.DeviceEventManagerModule
16+
import com.facebook.react.uimanager.ThemedReactContext
1717
import com.facebook.react.uimanager.UIManagerHelper
1818
import com.facebook.react.uimanager.events.Event
1919
import com.facebook.react.uimanager.events.EventDispatcher
@@ -26,7 +26,7 @@ class KeyboardAnimationCallback(
2626
val persistentInsetTypes: Int,
2727
val deferredInsetTypes: Int,
2828
dispatchMode: Int = DISPATCH_MODE_STOP,
29-
val context: ReactApplicationContext?,
29+
val context: ThemedReactContext?,
3030
val onApplyWindowInsetsListener: OnApplyWindowInsetsListener,
3131
) : WindowInsetsAnimationCompat.Callback(dispatchMode), OnApplyWindowInsetsListener {
3232
private val TAG = KeyboardAnimationCallback::class.qualifiedName

android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardControllerViewManagerImpl.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import com.reactnativekeyboardcontroller.KeyboardAnimationCallback
1313
import com.reactnativekeyboardcontroller.R
1414
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup
1515

16-
class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
16+
class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicationContext) {
1717
private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
18-
private var mReactContext = reactContext
1918
private var isStatusBarTranslucent = false
2019

2120
fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
2221
val view = EdgeToEdgeReactViewGroup(reactContext)
23-
val activity = mReactContext.currentActivity
22+
val activity = reactContext.currentActivity
2423

2524
if (activity == null) {
2625
Log.w(TAG, "Can not setup keyboard animation listener, since `currentActivity` is null")
@@ -34,10 +33,10 @@ class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
3433
// We explicitly allow dispatch to continue down to binding.messageHolder's
3534
// child views, so that step 2.5 below receives the call
3635
dispatchMode = WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE,
37-
context = mReactContext,
36+
context = reactContext,
3837
onApplyWindowInsetsListener = { v, insets ->
3938
val content =
40-
mReactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
39+
reactContext.currentActivity?.window?.decorView?.rootView?.findViewById<FitWindowsLinearLayout>(
4140
R.id.action_bar_root,
4241
)
4342
content?.setPadding(

0 commit comments

Comments
 (0)