-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Conversation
Base commit: 1fc27c4 |
Hi @Abbondanzo! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Base commit: 1fc27c4 |
@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) { |
There was a problem hiding this comment.
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:
react-native/ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java
Lines 193 to 204 in c4f9556
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) { |
This pull request was successfully merged by @Abbondanzo in 5c5220a. When will my fix make it into a release? | Upcoming Releases |
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
… 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
… 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
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. Unlessandroid:windowLightStatusBar
is set to true, the default flag is a zero-integer (a.k.a. "dark mode", where the icons show as white). Since theStatusBar
component is using the newsetSystemBarsAppearance
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
StatusBar
bar style set todark-content
, the modal also uses white iconsStatusBar
bar style set tolight-content
, the modal also uses black iconsPreview
Here, I change the
barStyle
fromlight-content
todark-content
and demonstrate that the proper attributes are retained. The "Before" is a recording frommain
and the "After" is this branch. Notice how in "Before", the status bar is always turning the icons white when the modal opens.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