diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index 2b3de095d40..2ae3bb9bda3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -19,6 +19,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewStructure; import android.view.Window; +import android.view.WindowInsetsController; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.widget.FrameLayout; @@ -328,19 +329,7 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe } if (currentActivity != null && !currentActivity.isFinishing()) { mDialog.show(); - if (context instanceof Activity) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { - int appearance = - ((Activity) context).getWindow().getInsetsController().getSystemBarsAppearance(); - mDialog.getWindow().getInsetsController().setSystemBarsAppearance(appearance, appearance); - } else { - mDialog - .getWindow() - .getDecorView() - .setSystemUiVisibility( - ((Activity) context).getWindow().getDecorView().getSystemUiVisibility()); - } - } + updateSystemAppearance(); mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); } } @@ -394,6 +383,32 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe } } + private void updateSystemAppearance() { + Activity currentActivity = getCurrentActivity(); + if (currentActivity == null) { + return; + } + Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateSystemAppearance"); + // Modeled after the version check in StatusBarModule.setStyle + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) { + int activityAppearance = + currentActivity.getWindow().getInsetsController().getSystemBarsAppearance(); + int activityLightStatusBars = + activityAppearance & WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; + mDialog + .getWindow() + .getInsetsController() + .setSystemBarsAppearance( + activityLightStatusBars, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS); + } else { + mDialog + .getWindow() + .getDecorView() + .setSystemUiVisibility( + currentActivity.getWindow().getDecorView().getSystemUiVisibility()); + } + } + @Nullable public StateWrapper getStateWrapper() { return mHostView.getStateWrapper();