-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Implement system fonts system channel listener #38930
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
Conversation
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other objects/widgets that use TextPainter to measure text (example: CupertinoDataPicker or Material's TimePicker)? Do we not have to notify them as well so they can rebuild?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is about painting text, PaintingBinding is probably a better place for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There probably needs to be a public way to register listeners. Not all listeners are going to be RenderObjects (e.g. all the the non-RenderObject that use TextPainter, which are for example Widgets using CustomPaint like the TimePicker).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just pass in markNeedsLayout directly here? That way, interested RenderObjects would just have to implement the mixin and are good to go. (It also avoids an extra function call when this gets called).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is odd that the message bubbles up all the way to the widget layer and is then redirected back to the rendering layer. What if you've implemented your own Widget system based on Flutter's rendering layer? You still want the font thing to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: end with blank line.
|
Ready for re review @goderbauer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to include this to get passed doc parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this "RelayoutWhenSystemFontsChangeMixin" to better describe what it does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Mixin for [RenderObject] that will call [markNeedsLayout] whenever the system fonts change".
Can you also add an explanation why/when a developer should mix this in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would instance or systemFonts be null? Shouldn't they always be initialized when you get to this place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably find a better location then rendering/binding.dart for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe _SystemFontsListener
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awkward code to add to the framework. Can we find another way to test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling didChangeDependecies seems awkward (especially because that one calls super). Maybe factor out what you need from didChangeDependencies into a seperate method that we can call fro both places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handler called for messages received on the [SystemChannels.system] call.
Other bindings may override this to respond to incoming system message.
14dc007 to
e0856ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this statement into the setState closure? (That's the state getting changed here, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems outdated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this inside the setState since that's causing the state to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems outdated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment why we have to clear this on system font changes (e.g. because it was determined by measuring the width of text which may have changed with the new fonts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a text related painter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using ui.Paragraph directly without going through text painter. I should update the doc comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this import be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call -> message channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message -> messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from a switch?
3071459 to
f8d5bb9
Compare
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
1a86f0e to
2655235
Compare
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
@goderbauer this is ready to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how do we test _textPainter has been marked needs layout. this also apply to all the other widget.
The current test only verify renderobject is dirty after font change. unless I added a bunch of visibleforTesting for all the widgets that have textpainter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not have updated values? Isn't clearing the cache causing the values to get recalculated/updated?
Maybe:
"Clear cached width to ensure that they get recalculated with the new system fonts."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not really clearing a cache? It's proactively recalculating the widths?
(You could probably just remove the second line.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Listenable for OSes system fonts change event. | |
| /// Listenable that notifies when the fonts available on the system have changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this slightly awkward cast you could have a correctly typed private _systemFonts variable and a public systemFonts getter for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should include information about when somebody may want to call this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Called when system fonts have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subclasses should override this method to clear any cached values that depend on font-related metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, [mark needsLayout] is called on the [RenderObject] implementing this mixin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will _updateLabelPainter not automatically cause this to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will _updateLabelPainters not cause this to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, _updateLabelPainters will set the same property of existing textpainter, which will all get shortcircuited.
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no space after mark. (sorry...)
974dfa6 to
7b41a5f
Compare
614fefd to
75e1926
Compare
* Implement system fonts system channel listener
Description
This pr add a system channel listener to repaint RenderParagraph and RenderEditable upon receiving system fonts change notification. We will have engine side change coming soon
flutter/engine#12276
Related Issues
#38556
Tests
I added the following tests:
RenderParagraph relayout upon system fonts changes
RenderEditable relayout upon system fonts changes
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?