Fix regression in system UI colors (flutter/engine#28206)

This commit is contained in:
Kate Lovett
2021-08-19 23:42:02 -04:00
committed by GitHub
parent c4fb8a6051
commit 761409f61e
2 changed files with 49 additions and 20 deletions

View File

@@ -374,15 +374,17 @@ public class PlatformPlugin {
// If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure
// proper contrast. This can be overridden with
// SystemChromeStyle.systemStatusBarContrastEnforced.
if (systemChromeStyle.statusBarIconBrightness != null && Build.VERSION.SDK_INT >= 23) {
switch (systemChromeStyle.statusBarIconBrightness) {
case DARK:
// View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
flags |= 0x2000;
break;
case LIGHT:
flags &= ~0x2000;
break;
if (Build.VERSION.SDK_INT >= 23) {
if (systemChromeStyle.statusBarIconBrightness != null) {
switch (systemChromeStyle.statusBarIconBrightness) {
case DARK:
// View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
flags |= 0x2000;
break;
case LIGHT:
flags &= ~0x2000;
break;
}
}
if (systemChromeStyle.statusBarColor != null) {
@@ -403,16 +405,17 @@ public class PlatformPlugin {
// If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation
// bars to ensure proper contrast. This can be overridden with
// SystemChromeStyle.systemNavigationBarContrastEnforced.
if (systemChromeStyle.systemNavigationBarIconBrightness != null
&& Build.VERSION.SDK_INT >= 26) {
switch (systemChromeStyle.systemNavigationBarIconBrightness) {
case DARK:
// View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
flags |= 0x10;
break;
case LIGHT:
flags &= ~0x10;
break;
if (Build.VERSION.SDK_INT >= 26) {
if (systemChromeStyle.systemNavigationBarIconBrightness != null) {
switch (systemChromeStyle.systemNavigationBarIconBrightness) {
case DARK:
// View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
flags |= 0x10;
break;
case LIGHT:
flags &= ~0x10;
break;
}
}
if (systemChromeStyle.systemNavigationBarColor != null) {

View File

@@ -162,15 +162,41 @@ public class PlatformPluginTest {
when(fakeActivity.getWindow()).thenReturn(fakeWindow);
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
// Default style test
SystemChromeStyle style =
new SystemChromeStyle(0XFF000000, null, true, 0XFFC70039, null, 0XFF006DB3, true);
new SystemChromeStyle(
0XFF000000, // statusBarColor
null, // statusBarIconBrightness
true, // systemStatusBarContrastEnforced
0XFFC70039, // systemNavigationBarColor
null, // systemNavigationBarIconBrightness
0XFF006DB3, // systemNavigationBarDividerColor
true); // systemNavigationBarContrastEnforced
if (Build.VERSION.SDK_INT >= 28) {
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
assertEquals(0XFF000000, fakeActivity.getWindow().getStatusBarColor());
assertEquals(0XFFC70039, fakeActivity.getWindow().getNavigationBarColor());
assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor());
// Regression test for https://github.com/flutter/flutter/issues/88431
// A null brightness should not affect changing color settings.
style =
new SystemChromeStyle(
0XFF006DB3, // statusBarColor
null, // statusBarIconBrightness
true, // systemStatusBarContrastEnforced
0XFF000000, // systemNavigationBarColor
null, // systemNavigationBarIconBrightness
0XFF006DB3, // systemNavigationBarDividerColor
true); // systemNavigationBarContrastEnforced
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
assertEquals(0XFFC70039, fakeActivity.getWindow().getStatusBarColor());
assertEquals(0XFF000000, fakeActivity.getWindow().getNavigationBarColor());
assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor());
}
}