Skip to content

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Aug 29, 2017

What's implemented:

  • language categories
  • localized font sizes and font weights
  • Theme.of automatically localizes text properties in ThemeData based on the nearest available Localizations widget

What's not implemented:

  • language-specific text baseline (missing in the spec)
  • line height (lives in ParagraphStyle and not themeable in Flutter yet?)

Fixes #11771

/cc @Hixie @HansMuller

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space (or newline, typically preferred) after { for named arguments (and matching whitespace on the } side)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this configurable? This class is the en-US localisation but it's also the interface that other MaterialLocalizations implementations will implement or extend, so it doesn't really make sense for this to be a field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only needed it for testing. But now I'll wait for Hans' PR to go in so I can move this into the DefaultMaterialLocalizations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged with Hans' code. No changes necessary for typography.

Copy link
Contributor

Choose a reason for hiding this comment

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

this should just be hard-coded to the englishLike text theme, since this is the en-US default localisation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will become abstract after Hans' change.

Copy link
Contributor

Choose a reason for hiding this comment

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

these should be public since other packages that implement localisations will need to be able to refer to them.

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe all the dense ones should have an ideographic baseline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this table should exist. The actual localizations are where this information belongs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this go in the upcoming DefaultMaterialLocalizations? @HansMuller, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved under material/i18n/typography_localizations.dart.

Copy link
Contributor

Choose a reason for hiding this comment

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

I continue to this this table shouldn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably put the call to MaterialLocalizations.of(context) here too, so that all the inherited-widget logic is in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

how does this differ from the superclass implementation? if it does, please add a comment saying what the difference is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also deduped the logic a bit by moving it into a top-level function.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should add a TODO about the font fallback issue we discussed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Past experience has suggested that it's better if the call sites do the defaulting rather than the .of functions. It's ok to return null if there's no _LocalizationsScope in scope (though then you should document that that will happen), but we shouldn't default.

The problem with defaulting is that people don't know the value came from window, so they don't think to set up the onLocaleChanged handler. We saw this a lot with MediaQuery.of defaulting its padding to window.padding if it couldn't find a MediaQuery.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rolled back this change. Turns out I don't need it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please document that this returns null if there's no _LocalizationsScope in scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

D'oh! I forgot to hit the "Submit review" button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only needed it for testing. But now I'll wait for Hans' PR to go in so I can move this into the DefaultMaterialLocalizations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will become abstract after Hans' change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this go in the upcoming DefaultMaterialLocalizations? @HansMuller, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also deduped the logic a bit by moving it into a top-level function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rolled back this change. Turns out I don't need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 8, 2017

Merged this with Hans' changes. This is ready for review again. PTAL.

@Hixie
Copy link
Contributor

Hixie commented Sep 9, 2017

I don't think we should have the table. The kind of typography needed should be a part of the actual localization object, just like whether we're LTR or RTL, what the strings are, etc. That way there's no difference between how we do things and how someone would create a new localization. It's a cleaner separation of concerns and layering.

@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 12, 2017

I don't think we should have the table.

WDYT of fcb19a3?

@Hixie
Copy link
Contributor

Hixie commented Sep 12, 2017

That's much better, but it seems like it'd be even better if the localizations just returned the TextTheme directly.

@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 12, 2017

it'd be even better if the localizations just returned the TextTheme directly

Yep, it does. This PR adds MaterialLocalizations.localTextGeometry getter. The fact that everything is stuffed in a global const map is an implementation detail of our current i18n infrastructure, which we can improve without breaking changes later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does "The text styles provided by this theme are inherited" mean that localTextGeometry's TextStyles will be inherit:true, or inherit:false? I think we should be more explicit about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

just remove @immutable on the superclass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

are these fontSizes/fontWeights/baselines ever actually used? Can we get away with not specifying them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on what you mean by "actually used". Today we support using Typography without the Theme. Example:

  testWidgets('geometry defaults are used', (WidgetTester tester) {
    final Typography typography = new Typography(platform: TargetPlatform.android);
    tester.pumpWidget(new Directionality(
      textDirection: TextDirection.ltr,
      child: new Text('Hello', style: typography.white.body1),
    ));
  });

I'm not sure if our sample apps use it in this way. Probably rarely or not at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed fontSizes/fontWeights/baselines in 98612e0. Wasn't a big deal for our tests.

@yjbanov yjbanov force-pushed the typography branch 2 times, most recently from 8da8191 to 98612e0 Compare September 15, 2017 00:40
@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 15, 2017

PTAL

@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 18, 2017

Ping? The PR keeps getting outdated as things get added to localizations.dart. I'd like to submit it asap.

@Hixie
Copy link
Contributor

Hixie commented Sep 20, 2017

LGTM

@yjbanov yjbanov force-pushed the typography branch 2 times, most recently from ba87dc7 to 54fe7ee Compare September 21, 2017 00:19
@yjbanov yjbanov merged commit b9e1be9 into flutter:master Sep 22, 2017
@Hixie
Copy link
Contributor

Hixie commented Sep 25, 2017

This caused a noticeably regression of the stock_build_iteration benchmark.

@yjbanov
Copy link
Contributor Author

yjbanov commented Sep 25, 2017

Looking into it: #12247

@tvolkert
Copy link
Contributor

FYI, this broke tests in package:flutter_markdown - MarkdownStyleSheet.fromTheme() assumes that it's passed a complete ThemeData instance.

Should:

  1. MarkdownStyleSheet.fromTheme() assert that the theme data is complete (in order to provide a better failure mode than null * 0.85) and flutter_markdown_test.dart be updated to pass a complete theme data
  2. MarkdownStyleSheet.fromTheme() be updated to be tolerant of incomplete theme data?

@Hixie
Copy link
Contributor

Hixie commented Sep 29, 2017

MarkdownStyleSheet.fromTheme() should assert that the theme data is complete.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 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.

I18N Typography

4 participants