Skip to content

Commit

Permalink
fix: create view using context provided by createViewInstance method (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
kirillzyusko committed Feb 10, 2023
1 parent 894c192 commit 0cbada6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsAnimationCompat
import androidx.core.view.WindowInsetsCompat
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.events.Event
import com.facebook.react.uimanager.events.EventDispatcher
Expand All @@ -26,7 +26,7 @@ class KeyboardAnimationCallback(
val persistentInsetTypes: Int,
val deferredInsetTypes: Int,
dispatchMode: Int = DISPATCH_MODE_STOP,
val context: ReactApplicationContext?,
val context: ThemedReactContext?,
val onApplyWindowInsetsListener: OnApplyWindowInsetsListener,
) : WindowInsetsAnimationCompat.Callback(dispatchMode), OnApplyWindowInsetsListener {
private val TAG = KeyboardAnimationCallback::class.qualifiedName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import com.reactnativekeyboardcontroller.KeyboardAnimationCallback
import com.reactnativekeyboardcontroller.R
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup

class KeyboardControllerViewManagerImpl(reactContext: ReactApplicationContext) {
class KeyboardControllerViewManagerImpl(private val mReactContext: ReactApplicationContext) {
private val TAG = KeyboardControllerViewManagerImpl::class.qualifiedName
private var mReactContext = reactContext
private var isStatusBarTranslucent = false

fun createViewInstance(reactContext: ThemedReactContext): ReactViewGroup {
val view = EdgeToEdgeReactViewGroup(reactContext)
val activity = mReactContext.currentActivity
val activity = reactContext.currentActivity

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

0 comments on commit 0cbada6

Please sign in to comment.