Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import static com.facebook.react.uimanager.common.UIManagerType.FABRIC;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Point;
Expand Down Expand Up @@ -856,12 +854,18 @@ public void onGlobalLayout() {
checkForDeviceDimensionsChanges();
}

private Activity getActivity() {
Context context = getContext();
while (!(context instanceof Activity) && context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
private @Nullable WindowManager.LayoutParams getWindowLayoutParams() {
View view = ReactRootView.this;
if (view.getLayoutParams() instanceof WindowManager.LayoutParams) {
return (WindowManager.LayoutParams) view.getLayoutParams();
}
return (Activity) context;
while (view.getParent() instanceof View) {
view = (View) view.getParent();
if (view.getLayoutParams() instanceof WindowManager.LayoutParams) {
return (WindowManager.LayoutParams) view.getLayoutParams();
}
}
return null;
}

@RequiresApi(api = Build.VERSION_CODES.R)
Expand All @@ -881,7 +885,13 @@ private void checkForKeyboardEvents() {
Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars());
int height = imeInsets.bottom - barInsets.bottom;

int softInputMode = getActivity().getWindow().getAttributes().softInputMode;
int softInputMode;
WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
if (windowLayoutParams != null) {
softInputMode = windowLayoutParams.softInputMode;
} else {
return;
}
int screenY =
softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
? mVisibleViewArea.bottom - height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.graphics.Insets
import android.graphics.Rect
import android.view.MotionEvent
import android.view.WindowInsets
import android.view.WindowManager
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.CatalystInstance
import com.facebook.react.bridge.JavaOnlyArray
Expand Down Expand Up @@ -211,9 +212,11 @@ class RootViewTest {
.setVisible(WindowInsets.Type.ime(), true)
.build()
}
val rootViewSpy = spy(rootView)
whenever(rootViewSpy.getLayoutParams()).thenReturn(WindowManager.LayoutParams())

rootView.startReactApplication(instanceManager, "")
rootView.simulateCheckForKeyboardForTesting()
rootViewSpy.startReactApplication(instanceManager, "")
rootViewSpy.simulateCheckForKeyboardForTesting()

val params = Arguments.createMap()
val endCoordinates = Arguments.createMap()
Expand Down