Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 53bc600

Browse files
authored
Fix regression in system UI colors (#28206)
1 parent b20c1a3 commit 53bc600

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,17 @@ private void setSystemChromeSystemUIOverlayStyle(
374374
// If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure
375375
// proper contrast. This can be overridden with
376376
// SystemChromeStyle.systemStatusBarContrastEnforced.
377-
if (systemChromeStyle.statusBarIconBrightness != null && Build.VERSION.SDK_INT >= 23) {
378-
switch (systemChromeStyle.statusBarIconBrightness) {
379-
case DARK:
380-
// View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
381-
flags |= 0x2000;
382-
break;
383-
case LIGHT:
384-
flags &= ~0x2000;
385-
break;
377+
if (Build.VERSION.SDK_INT >= 23) {
378+
if (systemChromeStyle.statusBarIconBrightness != null) {
379+
switch (systemChromeStyle.statusBarIconBrightness) {
380+
case DARK:
381+
// View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
382+
flags |= 0x2000;
383+
break;
384+
case LIGHT:
385+
flags &= ~0x2000;
386+
break;
387+
}
386388
}
387389

388390
if (systemChromeStyle.statusBarColor != null) {
@@ -403,16 +405,17 @@ private void setSystemChromeSystemUIOverlayStyle(
403405
// If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation
404406
// bars to ensure proper contrast. This can be overridden with
405407
// SystemChromeStyle.systemNavigationBarContrastEnforced.
406-
if (systemChromeStyle.systemNavigationBarIconBrightness != null
407-
&& Build.VERSION.SDK_INT >= 26) {
408-
switch (systemChromeStyle.systemNavigationBarIconBrightness) {
409-
case DARK:
410-
// View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
411-
flags |= 0x10;
412-
break;
413-
case LIGHT:
414-
flags &= ~0x10;
415-
break;
408+
if (Build.VERSION.SDK_INT >= 26) {
409+
if (systemChromeStyle.systemNavigationBarIconBrightness != null) {
410+
switch (systemChromeStyle.systemNavigationBarIconBrightness) {
411+
case DARK:
412+
// View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
413+
flags |= 0x10;
414+
break;
415+
case LIGHT:
416+
flags &= ~0x10;
417+
break;
418+
}
416419
}
417420

418421
if (systemChromeStyle.systemNavigationBarColor != null) {

shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,41 @@ public void setNavigationBarDividerColor() {
162162
when(fakeActivity.getWindow()).thenReturn(fakeWindow);
163163
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
164164
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
165+
// Default style test
165166
SystemChromeStyle style =
166-
new SystemChromeStyle(0XFF000000, null, true, 0XFFC70039, null, 0XFF006DB3, true);
167+
new SystemChromeStyle(
168+
0XFF000000, // statusBarColor
169+
null, // statusBarIconBrightness
170+
true, // systemStatusBarContrastEnforced
171+
0XFFC70039, // systemNavigationBarColor
172+
null, // systemNavigationBarIconBrightness
173+
0XFF006DB3, // systemNavigationBarDividerColor
174+
true); // systemNavigationBarContrastEnforced
167175

168176
if (Build.VERSION.SDK_INT >= 28) {
169177
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
170178

179+
assertEquals(0XFF000000, fakeActivity.getWindow().getStatusBarColor());
180+
assertEquals(0XFFC70039, fakeActivity.getWindow().getNavigationBarColor());
171181
assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor());
182+
183+
// Regression test for https://github.com/flutter/flutter/issues/88431
184+
// A null brightness should not affect changing color settings.
185+
style =
186+
new SystemChromeStyle(
187+
0XFF006DB3, // statusBarColor
188+
null, // statusBarIconBrightness
189+
true, // systemStatusBarContrastEnforced
190+
0XFF000000, // systemNavigationBarColor
191+
null, // systemNavigationBarIconBrightness
192+
0XFF006DB3, // systemNavigationBarDividerColor
193+
true); // systemNavigationBarContrastEnforced
194+
195+
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
196+
172197
assertEquals(0XFFC70039, fakeActivity.getWindow().getStatusBarColor());
173198
assertEquals(0XFF000000, fakeActivity.getWindow().getNavigationBarColor());
199+
assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor());
174200
}
175201
}
176202

0 commit comments

Comments
 (0)