Skip to content

Commit

Permalink
Update contrast enforcement for null values (#29055)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piinks committed Oct 7, 2021
1 parent 7472a16 commit 221ca5e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Expand Up @@ -374,13 +374,13 @@ private SystemChromeStyle decodeSystemChromeStyle(@NonNull JSONObject encodedSty
// 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");
Expand Down Expand Up @@ -684,22 +684,22 @@ public static class SystemChromeStyle {
// 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;
Expand Down
Expand Up @@ -393,7 +393,7 @@ private void setSystemChromeSystemUIOverlayStyle(
// 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);
}

Expand Down Expand Up @@ -432,7 +432,8 @@ private void setSystemChromeSystemUIOverlayStyle(
// 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);
}
Expand Down
Expand Up @@ -169,24 +169,50 @@ public void setNavigationBarDividerColor() {
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.
style =
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);
}
}

Expand Down

0 comments on commit 221ca5e

Please sign in to comment.