From 5c5220a46d05fa070e9f5f990bd741efa2b09309 Mon Sep 17 00:00:00 2001 From: Peter Abbondanzo Date: Tue, 11 Oct 2022 10:50:05 -0700 Subject: [PATCH] Check for system bars apperance on newer SDKs (#34899) Summary: As identified in https://github.com/facebook/react-native/issues/34350, modals do not honor the system's status bar colors because they may not be set by the deprecated `systemUiVisibility` flags. Unless `android:windowLightStatusBar` is set to true, the default flag is a zero-integer (a.k.a. "dark mode", where the icons show as white). Since the `StatusBar` component is using the new `setSystemBarsAppearance` API, the ModalHost should also infer its status bar settings from the same API. ## Changelog [Android] [Fixed] - Fixed an issue on Android API 31+ where modals would turn status bar icons white by default Pull Request resolved: https://github.com/facebook/react-native/pull/34899 Test Plan: - On a screen with the `StatusBar` bar style set to `dark-content`, the modal also uses white icons - On a screen with the `StatusBar` bar style set to `light-content`, the modal also uses black icons ### Preview Here, I change the `barStyle` from `light-content` to `dark-content` and demonstrate that the proper attributes are retained. The "Before" is a recording from `main` and the "After" is this branch. Notice how in "Before", the status bar is always turning the icons white when the modal opens. |Before|After| |-|-| |![ezgif-5-586e81991d](https://user-images.githubusercontent.com/10366495/194954666-71f69bd6-c02a-4725-9562-e1f5fcfdeddf.gif)|![ezgif-5-b212d7bb01](https://user-images.githubusercontent.com/10366495/194954244-9c205821-1d7f-4630-861b-f5dbe207f7cd.gif)| ## Other considerations There's some argument towards removing this check entirely--the status bar appearance should be derived from the theming and/or the parent activity's settings, thereby removing the need to apply separate styling Reviewed By: lunaleaps Differential Revision: D40243122 Pulled By: lunaleaps fbshipit-source-id: ffa56c7d6a1906f89658f95a12f6bf1cefd5be8e --- .../react/views/modal/ReactModalHostView.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index 2840de71e0b8db..82be75a4377fc9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -12,6 +12,7 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.os.Build; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -326,11 +327,17 @@ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (currentActivity != null && !currentActivity.isFinishing()) { mDialog.show(); if (context instanceof Activity) { - mDialog - .getWindow() - .getDecorView() - .setSystemUiVisibility( - ((Activity) context).getWindow().getDecorView().getSystemUiVisibility()); + 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()); + } } mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); }