Skip to content
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

[ui] Add null check in FontWeight.lerp #8274

Merged
merged 7 commits into from
Apr 2, 2019

Conversation

johnsonmh
Copy link
Contributor

Add a check to see if both a and b are null in FontWeight.lerp. If both are null, method should return null. Update comments to include this behavior.

Closes flutter/flutter#29816

@@ -80,6 +81,8 @@ class FontWeight {
/// an [AnimationController].
static FontWeight lerp(FontWeight a, FontWeight b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

In practice, since LibTxt's TextStyle defaults null font weights to w400, and dart:ui's FontWeight and TextStyle are only created as the final step before passing the data into native code, this change should cause minimal real-world impact.

The case where this makes a difference is when the user intended the font weight to inherit from a previous TextStyle in the stack. The behavior suggested here would allow it to inherit instead of be set to w400. On the framework side, the inherit flag can also be used to force inherit behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was there any specific case where the old behavior was causing unexpected behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only noticed it because I was experimenting with a change to BottomNavigationBar in the framework. Basically I wanted to add the fields: TextStyle selectedLabelStyle and TextStyle unselectedLabelStyle. Then, the bottom nav would lerp between the two text styles so that they would animate properly.

I noticed in my tests that this was adding a FontWeight.w400 somewhat unexpectedly, since pretty much every other [field on the TextStyle class] lerps to return null. Like lerpDouble and Color.lerp.

@GaryQian
Copy link
Contributor

The change/code looks good, but wanted to run it through some people to better understand what the expected lerp behavior is.

@johnsonmh
Copy link
Contributor Author

johnsonmh commented Apr 1, 2019

@GaryQian Sounds good, let me know when you have any updates or hear any new opinions.

Also, I added a couple unit tests.

@GaryQian
Copy link
Contributor

GaryQian commented Apr 1, 2019

So @Hixie indicated he is ok with this change. We should make sure to go through the breaking change process at https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes before landing this. Let me know if you want to do it, if not, I can.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

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

LGTM, pending breaking change announcement.

@johnsonmh
Copy link
Contributor Author

I've actually already sent out a breaking change request: https://groups.google.com/forum/m/?utm_medium=email&utm_source=footer#!topic/flutter-announce/0uS_Hzq894I

This went out a week ago, didn't get any comments on it, do you think it's OK to submit?

@GaryQian
Copy link
Contributor

GaryQian commented Apr 2, 2019

Ahh ok, sure, that sounds good, go ahead!

@johnsonmh johnsonmh merged commit 3796d98 into flutter:master Apr 2, 2019
@johnsonmh johnsonmh deleted the fix-fontWeightLerp branch April 2, 2019 01:57
@willlarche
Copy link
Member

LGTM!!!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 2, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Apr 2, 2019
…30352)

flutter/engine@79a988f...3796d98

git log 79a988f..3796d98 --no-merges --oneline
3796d98 [ui] Add null check in FontWeight.lerp (flutter/engine#8274)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (bmparr@google.com), and stop
the roller if necessary.
RBogie pushed a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
* Add null check in FontWeight.lerp

* Add Unit tests for FontWeight.lerp
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants