Update contrast enforcement for null values (flutter/engine#29055)
This commit is contained in:
@@ -374,13 +374,13 @@ public class PlatformChannel {
|
||||
// TODO(mattcarroll): add color annotation
|
||||
Integer statusBarColor = null;
|
||||
Brightness statusBarIconBrightness = null;
|
||||
boolean systemStatusBarContrastEnforced = true;
|
||||
Boolean systemStatusBarContrastEnforced = null;
|
||||
// TODO(mattcarroll): add color annotation
|
||||
Integer systemNavigationBarColor = null;
|
||||
Brightness systemNavigationBarIconBrightness = null;
|
||||
// TODO(mattcarroll): add color annotation
|
||||
Integer systemNavigationBarDividerColor = null;
|
||||
boolean systemNavigationBarContrastEnforced = true;
|
||||
Boolean systemNavigationBarContrastEnforced = null;
|
||||
|
||||
if (!encodedStyle.isNull("statusBarColor")) {
|
||||
statusBarColor = encodedStyle.getInt("statusBarColor");
|
||||
@@ -684,22 +684,22 @@ public class PlatformChannel {
|
||||
// TODO(mattcarroll): add color annotation
|
||||
@Nullable public final Integer statusBarColor;
|
||||
@Nullable public final Brightness statusBarIconBrightness;
|
||||
@Nullable public final boolean systemStatusBarContrastEnforced;
|
||||
@Nullable public final Boolean systemStatusBarContrastEnforced;
|
||||
// TODO(mattcarroll): add color annotation
|
||||
@Nullable public final Integer systemNavigationBarColor;
|
||||
@Nullable public final Brightness systemNavigationBarIconBrightness;
|
||||
// TODO(mattcarroll): add color annotation
|
||||
@Nullable public final Integer systemNavigationBarDividerColor;
|
||||
@Nullable public final boolean systemNavigationBarContrastEnforced;
|
||||
@Nullable public final Boolean systemNavigationBarContrastEnforced;
|
||||
|
||||
public SystemChromeStyle(
|
||||
@Nullable Integer statusBarColor,
|
||||
@Nullable Brightness statusBarIconBrightness,
|
||||
@Nullable boolean systemStatusBarContrastEnforced,
|
||||
@Nullable Boolean systemStatusBarContrastEnforced,
|
||||
@Nullable Integer systemNavigationBarColor,
|
||||
@Nullable Brightness systemNavigationBarIconBrightness,
|
||||
@Nullable Integer systemNavigationBarDividerColor,
|
||||
@Nullable boolean systemNavigationBarContrastEnforced) {
|
||||
@Nullable Boolean systemNavigationBarContrastEnforced) {
|
||||
this.statusBarColor = statusBarColor;
|
||||
this.statusBarIconBrightness = statusBarIconBrightness;
|
||||
this.systemStatusBarContrastEnforced = systemStatusBarContrastEnforced;
|
||||
|
||||
@@ -393,7 +393,7 @@ public class PlatformPlugin {
|
||||
// You can't override the enforced contrast for a transparent status bar until SDK 29.
|
||||
// This overrides the translucent scrim that may be placed behind the bar on SDK 29+ to ensure
|
||||
// contrast is appropriate when using full screen layout modes like Edge to Edge.
|
||||
if (!systemChromeStyle.systemStatusBarContrastEnforced && Build.VERSION.SDK_INT >= 29) {
|
||||
if (systemChromeStyle.systemStatusBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) {
|
||||
window.setStatusBarContrastEnforced(systemChromeStyle.systemStatusBarContrastEnforced);
|
||||
}
|
||||
|
||||
@@ -432,7 +432,8 @@ public class PlatformPlugin {
|
||||
// This overrides the translucent scrim that may be placed behind 2/3 button navigation bars on
|
||||
// SDK 29+ to ensure contrast is appropriate when using full screen layout modes like
|
||||
// Edge to Edge.
|
||||
if (!systemChromeStyle.systemNavigationBarContrastEnforced && Build.VERSION.SDK_INT >= 29) {
|
||||
if (systemChromeStyle.systemNavigationBarContrastEnforced != null
|
||||
&& Build.VERSION.SDK_INT >= 29) {
|
||||
window.setNavigationBarContrastEnforced(
|
||||
systemChromeStyle.systemNavigationBarContrastEnforced);
|
||||
}
|
||||
|
||||
@@ -169,6 +169,8 @@ public class PlatformPluginTest {
|
||||
verify(fakeWindow).setStatusBarColor(0xFF000000);
|
||||
verify(fakeWindow).setNavigationBarColor(0XFFC70039);
|
||||
verify(fakeWindow).setNavigationBarDividerColor(0XFF006DB3);
|
||||
verify(fakeWindow).setStatusBarContrastEnforced(true);
|
||||
verify(fakeWindow).setNavigationBarContrastEnforced(true);
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/88431
|
||||
// A null brightness should not affect changing color settings.
|
||||
@@ -176,17 +178,41 @@ public class PlatformPluginTest {
|
||||
new SystemChromeStyle(
|
||||
0XFF006DB3, // statusBarColor
|
||||
null, // statusBarIconBrightness
|
||||
true, // systemStatusBarContrastEnforced
|
||||
false, // systemStatusBarContrastEnforced
|
||||
0XFF000000, // systemNavigationBarColor
|
||||
null, // systemNavigationBarIconBrightness
|
||||
0XFF006DB3, // systemNavigationBarDividerColor
|
||||
true); // systemNavigationBarContrastEnforced
|
||||
false); // systemNavigationBarContrastEnforced
|
||||
|
||||
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
|
||||
|
||||
verify(fakeWindow).setStatusBarColor(0XFF006DB3);
|
||||
verify(fakeWindow).setNavigationBarColor(0XFF000000);
|
||||
verify(fakeWindow, times(2)).setNavigationBarDividerColor(0XFF006DB3);
|
||||
verify(fakeWindow).setStatusBarContrastEnforced(false);
|
||||
verify(fakeWindow).setNavigationBarContrastEnforced(false);
|
||||
|
||||
// Null contrasts values should be allowed.
|
||||
style =
|
||||
new SystemChromeStyle(
|
||||
0XFF006DB3, // statusBarColor
|
||||
null, // statusBarIconBrightness
|
||||
null, // systemStatusBarContrastEnforced
|
||||
0XFF000000, // systemNavigationBarColor
|
||||
null, // systemNavigationBarIconBrightness
|
||||
0XFF006DB3, // systemNavigationBarDividerColor
|
||||
null); // systemNavigationBarContrastEnforced
|
||||
|
||||
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
|
||||
|
||||
verify(fakeWindow, times(2)).setStatusBarColor(0XFF006DB3);
|
||||
verify(fakeWindow, times(2)).setNavigationBarColor(0XFF000000);
|
||||
verify(fakeWindow, times(3)).setNavigationBarDividerColor(0XFF006DB3);
|
||||
// Count is 1 each from earlier calls
|
||||
verify(fakeWindow, times(1)).setStatusBarContrastEnforced(true);
|
||||
verify(fakeWindow, times(1)).setNavigationBarContrastEnforced(true);
|
||||
verify(fakeWindow, times(1)).setStatusBarContrastEnforced(false);
|
||||
verify(fakeWindow, times(1)).setNavigationBarContrastEnforced(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user