Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for system bars apperance on newer SDKs #34899

Closed
wants to merge 3 commits into from
Closed

Check for system bars apperance on newer SDKs #34899

wants to merge 3 commits into from

Conversation

Abbondanzo
Copy link
Contributor

@Abbondanzo Abbondanzo commented Oct 7, 2022

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. Some additional context can be found in my comment here.

Changelog

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

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 ezgif-5-b212d7bb01

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

@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Oct 7, 2022
@analysis-bot
Copy link

analysis-bot commented Oct 7, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 1fc27c4
Branch: main

@facebook-github-bot
Copy link
Contributor

Hi @Abbondanzo!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added the No CLA Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2022
@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label Oct 8, 2022
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,746,543 -21,951
android hermes armeabi-v7a 7,148,477 -20,971
android hermes x86 8,057,618 -24,021
android hermes x86_64 8,028,672 -24,459
android jsc arm64-v8a 9,608,219 -21,163
android jsc armeabi-v7a 8,373,462 -20,346
android jsc x86 9,555,483 -23,318
android jsc x86_64 10,148,012 -23,882

Base commit: 1fc27c4
Branch: main

@Abbondanzo Abbondanzo marked this pull request as ready for review October 10, 2022 21:26
@facebook-github-bot
Copy link
Contributor

@makovkastar has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

.getDecorView()
.setSystemUiVisibility(
((Activity) context).getWindow().getDecorView().getSystemUiVisibility());
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StatusBarModule makes this same if/else check, so reimplementing it here:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
WindowInsetsController insetsController = activity.getWindow().getInsetsController();
if ("dark-content".equals(style)) {
// dark-content means dark icons on a light status bar
insetsController.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
} else {
insetsController.setSystemBarsAppearance(
0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @Abbondanzo in 5c5220a.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 11, 2022
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
As identified in facebook#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: facebook#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
facebook-github-bot pushed a commit that referenced this pull request Oct 31, 2023
… modals (#40979)

Summary:
The current ReactModalHostView implementation incorrectly applies system bar appearances by providing the wrong mask to the `setSystemBarsAppearance` method invocation. Per [this issue comment](#34350 (comment)), jaydonlau correctly identified that when the status bar is set to `light-content` (light icons, dark background), the function is called with both a `0` appearance and `0` mask, which should instead be provided with the `APPEARANCE_LIGHT_STATUS_BARS` mask.

The first pass at this PR attempted to pull out the entire appearance from the activity, compare it against the dialog's appearance, and only use a mask of differing bits (see the `appearanceMask` variable). However, if the `android:windowLightStatusBar` attribute is ever set to true, this does not impact the appearance of the status bar but rather the system UI visibility. As a result, the derived mask from system bars appearance would be 0 since both the activity and dialog would have appearances of 0.

Rather than try and "future-proof" this implementation for other uses of system bar appearance, this change is directed only at updating the `APPEARANCE_LIGHT_STATUS_BARS` bit in the dialog's system bar appearance. The only other native code that touches status bars is the `StatusBarModule` and that only touches this flag.

This is a follow-up to #34899.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [FIXED] - Fixed an issue where the status bar colors would not match when opening modals

Pull Request resolved: #40979

Test Plan:
First test:
- Replace the `RNTesterAppShared` implementation with the implementation from [this Expo snack](https://snack.expo.dev/abbondanzo/status-bar-tester)
- Toggle the status bar to show dark icons, open the modal and ensure that dark icons are displayed
- Toggle the status bar to show light icons, open the modal and ensure that light icons are displayed

Second test:
- Set the `android:windowLightStatusBar` attribute to true in the `AppTheme`
- Follow the steps from the First test above, guaranteeing that status bar appearance overrides the theme

Reviewed By: NickGerleman

Differential Revision: D50329714

Pulled By: luluwu2032

fbshipit-source-id: 26ecaca05f8e00a52e13767e468b552ac167fc98
Othinn pushed a commit to Othinn/react-native that referenced this pull request Jan 9, 2024
… modals (facebook#40979)

Summary:
The current ReactModalHostView implementation incorrectly applies system bar appearances by providing the wrong mask to the `setSystemBarsAppearance` method invocation. Per [this issue comment](facebook#34350 (comment)), jaydonlau correctly identified that when the status bar is set to `light-content` (light icons, dark background), the function is called with both a `0` appearance and `0` mask, which should instead be provided with the `APPEARANCE_LIGHT_STATUS_BARS` mask.

The first pass at this PR attempted to pull out the entire appearance from the activity, compare it against the dialog's appearance, and only use a mask of differing bits (see the `appearanceMask` variable). However, if the `android:windowLightStatusBar` attribute is ever set to true, this does not impact the appearance of the status bar but rather the system UI visibility. As a result, the derived mask from system bars appearance would be 0 since both the activity and dialog would have appearances of 0.

Rather than try and "future-proof" this implementation for other uses of system bar appearance, this change is directed only at updating the `APPEARANCE_LIGHT_STATUS_BARS` bit in the dialog's system bar appearance. The only other native code that touches status bars is the `StatusBarModule` and that only touches this flag.

This is a follow-up to facebook#34899.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [FIXED] - Fixed an issue where the status bar colors would not match when opening modals

Pull Request resolved: facebook#40979

Test Plan:
First test:
- Replace the `RNTesterAppShared` implementation with the implementation from [this Expo snack](https://snack.expo.dev/abbondanzo/status-bar-tester)
- Toggle the status bar to show dark icons, open the modal and ensure that dark icons are displayed
- Toggle the status bar to show light icons, open the modal and ensure that light icons are displayed

Second test:
- Set the `android:windowLightStatusBar` attribute to true in the `AppTheme`
- Follow the steps from the First test above, guaranteeing that status bar appearance overrides the theme

Reviewed By: NickGerleman

Differential Revision: D50329714

Pulled By: luluwu2032

fbshipit-source-id: 26ecaca05f8e00a52e13767e468b552ac167fc98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants