Fix regression in system UI colors (flutter/engine#28206)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user