Skip to content

Commit

Permalink
Check for system bars apperance on newer SDKs (#34899)
Browse files Browse the repository at this point in the history
Summary:
As identified in #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

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Fixed] - Fixed an issue on Android API 31+ where modals would turn status bar icons white by default

Pull Request resolved: #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
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 11, 2022
1 parent 4d1a568 commit 5c5220a
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5c5220a

Please sign in to comment.