Skip to content

Extend SystemUiOverlayStyle with additonal values for each platform - #17171

Merged
jonahwilliams merged 14 commits into
flutter:masterfrom
jonahwilliams:system_chrome
May 10, 2018
Merged

jonahwilliams merged 14 commits into
flutter:masterfrom
jonahwilliams:system_chrome

Conversation

@jonahwilliams

@jonahwilliams jonahwilliams commented May 1, 2018 •

Copy link
Copy Markdown
Contributor

Requires flutter-team-archive/engine#5112. See this PR for more context

Work towards full support for #16837

/// applications with a dark background.
light,
static const SystemUiOverlayStyle light = const SystemUiOverlayStyle(
navigationBarColor: 0xFF000000,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Black seems at odds with overlays should be drawn with a light color

@jonahwilliams jonahwilliams May 2, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me do another pass on these values... I keep getting my wires crossed whether we are referring to the color of the UI or the color to match the UI.

/// applications with a light background.
dark,
static const SystemUiOverlayStyle dark = const SystemUiOverlayStyle(
navigationBarColor: 0xFFFFFFFF,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White seems at odds with overlays should be drawn with a dark color.

Shouldn't this version specify a navigationDividerColor (because a non-white divider looks best on white).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed colors.

I can add a divider color, but we can't actually invoke that API until we update our target SDK version to P though. We can address this later if we decide to draw the bar ourselves using a transparent navigation bar

/// The color of the divider between the bottom navigation and content.
///
/// Only honored in Android versions P and greater.
final int navigationDividerColor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of consistency (but not brevity): navigationBarDividerColor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// Only honored in Android versions O and greater.
final int navigationBarColor;

/// The color of the divider between the bottom navigation and content.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

between the systems bottom navigation bar and the app's content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/// Specifies a dark vs light preference for certain system chrome options.
enum SystemChromeTheme {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using FooTheme to name inherited widgets (typically configured with FooData) that configure visuals for descendant Foo widgets.

Instead of defining a new enum here, could we use Brightness

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. brightness was defined in material so I pulled it into services and re-exported from theme_data. Let me know if there is a better approach here, I didn't think that services should import material since it is supposed to be at a lower level

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having services provide Brightness sounds sensible to me.

this.navigationIconTheme,
});

/// The color of the bottom navigation bar.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the doc's context informs otherwise, think it's worth qualifying this as the "system" navigation bar to avoid confusion with BottomNavigationBar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// The theme of the navigation bar buttons.
///
/// Only honored in Android versions O and greater.
final SystemChromeTheme navigationIconTheme;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folding in earlier naming suggestions: Brightness navigationBarIconBrightness

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// The color of top status bar.
///
/// Only honored in Android version O and greater.
final int statusBarColor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a Color here (and pass along it's int value)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// The theme of top status bar.
///
/// Only honored in iOS and Android version O and greater.
final SystemChromeTheme statusBarTheme;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Folding in earlier naming suggestions: Brightness statusBarBrightness

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - split into statusBarBrightness and statusBarIconBrightness

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

To keep this from being a breaking change, I have added checks to prevent the light theme from being set for Android. These checks can be removed when I add platform themes and clean up the app bars

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

Actually it looks like some of these properties can be used before O. I will double check everything and update

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

flutter-team-archive/engine#5112 is merged into flutter/flutter, @HansMuller PTAL when you have a minute

@HansMuller HansMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small-time feedback about the details.

light,
static const SystemUiOverlayStyle light = const SystemUiOverlayStyle(
systemNavigationBarColor: const Color(0xFFFFFFFF),
systemNavigationBarDividerColor: null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want a shade of gray here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I haven't gotten a chance to play with the P preview I don't really know what the behavior is. null makes sure the API isn't invoked yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I imagine that we'll have to render this divider on the framework side anyway.

/// Only honored in Android version M and greater.
final Brightness statusBarIconBrightness;

/// The brightness of the system navigation bar icons.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a little tidier if this definition was next to the other system nav bar defs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

@override
int get hashCode =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually reserve => for one-liners that return a value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

final Brightness systemNavigationBarIconBrightness;

/// Convert this event to a map for serialization.
Map<String, dynamic> toMap() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is just for communicating with the native code, so _toMap()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}

List<String> _stringify(List<dynamic> list) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be written or just inlined as

list.map((item) => item.toString()).toList()

The toList() might not be needed either, depending the implementation of invokeMethod.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't write this code so I'm going to leave it as is

@jonahwilliams
jonahwilliams merged commit 5732219 into flutter:master May 10, 2018
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
SystemChrome.setSystemUIOverlayStyle(
darkBackground ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark
);
// TODO(jonahwilliams): remove once we have platform themes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general i wouldn't bother with this kind of TODO. Either we eventually add platform themes and remove it, or we don't and this TODO isn't necessary.

I recommend reserving TODOs for more fundamental things where we know there's a limitation to the current implementation but we are intentionally cutting corners for some reason (e.g. because we are waiting an upstream fix).

return false;
final SystemUiOverlayStyle typedOther = other;
return typedOther.systemNavigationBarColor == systemNavigationBarColor
&& typedOther.systemNavigationBarDividerColor == systemNavigationBarDividerColor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be indented so that the expressions line up

@jonahwilliams
jonahwilliams deleted the system_chrome branch July 20, 2018 19:26
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants