Skip to content

Platform-specific typography #6634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Nov 1, 2016

No description provided.

const Typography._(this.black, this.white);

/// Returns the default typography for the specified platform.
static Typography forPlatform(TargetPlatform platform) {
Copy link
Member Author

@cbracken cbracken Nov 1, 2016

Choose a reason for hiding this comment

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

Thoughts on static forPlatform vs a factory ctor with required TargetPlatform? The only precedent I could find for a sort-of similar platform-specific ctor was the scroll behaviour delegate, but that's a type that actually gets used as a delegate as opposed to this case, which is just a util lookup.

Another option would be to just add black/white getters that take a platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand what you're asking.

Copy link
Member Author

@cbracken cbracken Nov 2, 2016

Choose a reason for hiding this comment

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

Basically, anyone have a preference for factory Typography({@required TargetPlatform platform}) vs the code in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yes. I think I prefer the constructor.

Also, constructor before fields please.

Copy link
Contributor

Choose a reason for hiding this comment

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

(the rule is "code should be in the order it's run", to make it easier to read. The constructors are run before you do anything with fields, hence they go first.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@cbracken cbracken force-pushed the platform-specific-typography branch from 7dd9d08 to 41c4b98 Compare November 2, 2016 00:45
@cbracken
Copy link
Member Author

cbracken commented Nov 2, 2016

Rebased this on top of #6640 to get the tests happy.

@@ -358,6 +356,9 @@ class CardCollectionState extends State<CardCollection> {
if (_dismissDirection == DismissDirection.endToStart)
rightArrowIcon = new Opacity(opacity: 0.1, child: rightArrowIcon);

ThemeData theme = Theme.of(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

these can be final

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -41,6 +41,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {

@override
Widget build(BuildContext context) {
TextTheme textTheme = Theme.of(context).textTheme;
Copy link
Contributor

Choose a reason for hiding this comment

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

these can be final

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -77,6 +78,32 @@ class TextTheme {
caption = const TextStyle(fontFamily: 'Roboto', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, color: Colors.white70, textBaseline: TextBaseline.alphabetic),
button = const TextStyle(fontFamily: 'Roboto', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, color: Colors.white, textBaseline: TextBaseline.alphabetic);

Copy link
Contributor

Choose a reason for hiding this comment

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

rename _black and _white as well.

Maybe blackMountainView and blackCupertino etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it. Done.

@cbracken cbracken force-pushed the platform-specific-typography branch 5 times, most recently from 23cd372 to 9685ce7 Compare November 2, 2016 16:57
@cbracken
Copy link
Member Author

cbracken commented Nov 2, 2016

Comments addressed and re-squashed. PTAL.

const Typography._(this.black, this.white);

/// Creates the default typography for the specified platform.
factory Typography({@required TargetPlatform platform}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: spaces around the arguments please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

switch (platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
typography = const Typography._(
Copy link
Contributor

Choose a reason for hiding this comment

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

you can just return here rather than setting a variable then returning it.
that also lets you remove the break.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

break;
}
assert(typography != null);
return typography;
Copy link
Contributor

Choose a reason for hiding this comment

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

then you'd just return null here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


/// Creates the default typography for the specified platform.
factory Typography({@required TargetPlatform platform}) {
Typography typography;
Copy link
Contributor

Choose a reason for hiding this comment

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

assert platform != null

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

/// material design. The black text theme, which uses dark glyphs, is used on
/// light backgrounds in light themes. The white text theme, which uses light
/// glyphs, is used in dark themes and on dark backgrounds in in light themes.
/// [black] and [white] define the two text themes used in material design. The
Copy link
Contributor

Choose a reason for hiding this comment

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

sentences should start with a capital letter. To make that work here, you can write it as something like The [black] and [white] properties provide...

Copy link
Member Author

Choose a reason for hiding this comment

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

Re-worded.

@Hixie
Copy link
Contributor

Hixie commented Nov 2, 2016

Ideally this would have some sort of test.

LGTM.

@cbracken cbracken force-pushed the platform-specific-typography branch 2 times, most recently from 0b6c035 to 227aa6d Compare November 2, 2016 18:12
@cbracken
Copy link
Member Author

cbracken commented Nov 2, 2016

Added a minimal test to ensure that typography is defined for all target platforms. Not a ton more we can test without getting into testing constants territory. Maybe just a test that iOS does its own thing?

@cbracken cbracken force-pushed the platform-specific-typography branch 2 times, most recently from 074300d to 43d7c33 Compare November 2, 2016 21:31
@cbracken
Copy link
Member Author

cbracken commented Nov 2, 2016

Added tests that ThemeData defaults to platform-specific font family and that ensure that we select the appropriate font family according to Apple's typography guidelines.

@cbracken cbracken force-pushed the platform-specific-typography branch from 43d7c33 to b805a6a Compare November 2, 2016 21:51
On Android and Fuchsia, default to Roboto. On iOS, use San Francisco.
@cbracken cbracken force-pushed the platform-specific-typography branch from b805a6a to 4875cda Compare November 2, 2016 22:23
@cbracken
Copy link
Member Author

cbracken commented Nov 2, 2016

Fixes #4956

@cbracken cbracken changed the title Platform specific typography Platform-specific typography Nov 2, 2016
@cbracken cbracken merged commit abcfc42 into flutter:master Nov 2, 2016
@cbracken cbracken deleted the platform-specific-typography branch January 24, 2017 03:52
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 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.

2 participants