diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 1ac3df2b2c08f5..cb480570ef10c2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -14,6 +14,7 @@ import android.app.Activity; import android.content.Context; +import android.content.ContextWrapper; import android.graphics.Canvas; import android.graphics.Insets; import android.graphics.Point; @@ -918,6 +919,14 @@ public void onGlobalLayout() { checkForDeviceDimensionsChanges(); } + private Activity getActivity() { + Context context = getContext(); + while (!(context instanceof Activity) && context instanceof ContextWrapper) { + context = ((ContextWrapper) context).getBaseContext(); + } + return (Activity) context; + } + @RequiresApi(api = Build.VERSION_CODES.R) private void checkForKeyboardEvents() { getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea); @@ -935,7 +944,7 @@ private void checkForKeyboardEvents() { Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars()); int height = imeInsets.bottom - barInsets.bottom; - int softInputMode = ((Activity) getContext()).getWindow().getAttributes().softInputMode; + int softInputMode = getActivity().getWindow().getAttributes().softInputMode; int screenY = softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING ? mVisibleViewArea.bottom - height