-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Move shared inline widget logic to RenderInlineWidgetContainerDefaults
#127308
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
Move shared inline widget logic to RenderInlineWidgetContainerDefaults
#127308
Conversation
chunhtai
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.
Just double check, is this also solving the issue of double scaling of the text widget inside inline widget?
| /// of the placeholder. | ||
| /// | ||
| /// Flutter widgets such as [TextField], [Text] and [RichText] do not recognize | ||
| /// [PlaceholderSpan] subclasses other than [WidgetSpan]. **Consider |
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.
If that is the case, should we deprecate PlaceholderSpan and expose widgetspan directly?
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 can add a typedef PlaceholderSpan = WidgetSpan; for a soft transition
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.
RenderEditable and RenderParagraph need to be moved to the widget library if we want to remove/deprecate PlaceholderSpan. Let me see if I can just hide PlaceholderSapn.
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.
Oh wait with the ParentDataWidget trick maybe we don't need the PlaceholderSpan class anymore.
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.
ah I see. I guess that is why the PlaceholderSpan was first introduced. I think we should avoid package level private.
we could use interface modifier, but people can still implements it.
Should it still be considered valid to extends PlaceHolderSpan if developer builds on top Rendering library without Widget library?
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.
Should it still be considered valid to extends PlaceHolderSpan if developer builds on top Rendering library without Widget library?
Yes but it would be very confusing when people write extends PlaceholderSpan, use the class in Text or TextField, and see their PlaceholderSpan class isn't working, and the inline widgets are all messed up. Like you said we could do a typedef and I think everything would work? well I forgot we can't import widget_span.dart there.
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.
Looks like it's possible to remove PlaceholderSpan from RenderEditable and RenderParagraph, I just have to replace TextParentData.span with TextParentData.alignment and TextParentData.baselineOffset. But it's probably for a different PR.
| String toString() =>'widget: $span, ${offset == null ? "not laid out" : "offset: $offset"}'; | ||
| } | ||
|
|
||
| /// A mixin that provides useful default behaviors for text [RenderBox]es |
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 are the defaults?
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.
The default layout/paint/hitTest implementations I assume. I followed this class: https://master-api.flutter.dev/flutter/rendering/RenderBoxContainerDefaultsMixin-mixin.html
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.
would be good to document these in the doc string
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.
Added documentation for when to call each default method.
It doesn't but my plan is to expose a flag |
That doesn't seem like a clean API though... we can continue the discussion in dd https://docs.google.com/document/d/1-DlElw3zWRDlqoc9z4YfkU9PbBwRTnc7NhLM97ljGwk/edit?disco=AAAAxR2fXig |
| /// [PlaceholderSpan] and may be used instead to specify a widget as the contents | ||
| /// of the placeholder. | ||
| /// | ||
| /// Flutter widgets such as [TextField], [Text] and [RichText] do not recognize |
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.
Is this a new limitation introduced by this PR? Or was this a problem before?
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.
Ah, is problem here that these classes all do type checks ala span is WidgetSpan? That's kinda unfortunate...
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.
Yeah PlaceholderSpan doesn't know how to generate renderable content (while WidgetSpan can), but in RenderEditable and RenderParagraph we can't do span is WidgetSpan unfortunately. But I think we'll be able to avoid referencing PlaceholderSpan in this mixin, since it's using ParentData instead of extracting the PlaceholderSpans from the InlineSpan tree.
| expect(paragraph.getMinIntrinsicWidth(0.0), 200); | ||
| }); | ||
|
|
||
| testWidgets('can compute IntrinsicHeight for widget span with text scaling', (WidgetTester tester) async { |
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: looks like this test is now testing IntrinsicHeight and Width? Maybe update the title?
| @override | ||
| @protected | ||
| bool hitTestChildren(BoxHitTestResult result, { required Offset position }) { | ||
| // Hit test text spans. |
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: this comment now seems kinda unnecessary?
| /// | ||
| /// * [WidgetSpan.extractFromInlineSpan], a helper function for extracting | ||
| /// [WidgetSpan]s from an [InlineSpan] tree. | ||
| mixin RenderInlineWidgetContainerDefaults on RenderBox, ContainerRenderObjectMixin<RenderBox, TextParentData> { |
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.
The naming here is a bit strange, "Widget" is a concept of the layer above rendering (where this is located in), so it technically doesn't have any knowledge of what a widget is.
Same for the method on this class that contain the name widget.
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 for the docs on this class. It should probably be rephrased to not be tied to the concept of widget (of course it can call out the WidgetSpan as an example...)
| ); | ||
| } | ||
|
|
||
| /// Computes the layout for every inline widget children using the given |
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 seems to operate on RenderBox children, though, not widgets?
| ]; | ||
| } | ||
|
|
||
| /// Positions each inline widget according to the coordinates provided in the |
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
| Offset? get offset => _offset; | ||
| Offset? _offset; | ||
|
|
||
| /// The [WidgetSpan] associated with this inline widget. |
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.
Its type is PlaceholderSpan, though?
| /// Helper function for extracting [WidgetSpan]s in preorder, from the given | ||
| /// [InlineSpan] as a list of widgets. | ||
| /// | ||
| /// The extracted widgets will be annotated with necessary semantics |
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 "necessary"? Necessary for what? :D
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.
Removed.
| /// | ||
| /// The extracted widgets will be annotated with necessary semantics | ||
| /// information. This function is used by [EditableText] and [RichText] so | ||
| /// calling it directly is rarely necessary. |
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 document the textScaleFactor param.
Also, for my own understanding: I thought we are getting rid of textScaleFactor?
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.
That's the next step. If it's ok I think I'll just replace textScaleFactor with textScaler without deprecating in the migration PR given nobody but the framework widgets are calling this method.
| if (child == null) { | ||
| return; | ||
| } | ||
| context.pushTransform( |
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.
Store the layerHandler this returns and pass it back in as oldLayer to give the engine more information for performance optimizations?
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.
Also, should we skip the transform if the scale is 1.0?
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
flutter/flutter@ee162e4...3db9504 2023-05-28 [email protected] Roll Flutter Engine from 340936f7c03c to a4d4ad9dae1a (1 revision) (flutter/flutter#127772) 2023-05-28 [email protected] Roll Flutter Engine from 57e491a46e05 to 340936f7c03c (1 revision) (flutter/flutter#127767) 2023-05-28 [email protected] Roll Flutter Engine from a37b1a38d97a to 57e491a46e05 (1 revision) (flutter/flutter#127765) 2023-05-28 [email protected] Roll Flutter Engine from b1698020bd57 to a37b1a38d97a (1 revision) (flutter/flutter#127761) 2023-05-27 [email protected] Roll Flutter Engine from 9e97c7379c7f to b1698020bd57 (1 revision) (flutter/flutter#127758) 2023-05-27 [email protected] Roll Flutter Engine from 0f38a0f0a18a to 9e97c7379c7f (1 revision) (flutter/flutter#127755) 2023-05-27 [email protected] Roll Flutter Engine from 1187168472a7 to 0f38a0f0a18a (1 revision) (flutter/flutter#127752) 2023-05-27 [email protected] Roll Flutter Engine from 3426cb827efb to 1187168472a7 (1 revision) (flutter/flutter#127745) 2023-05-27 [email protected] Roll Flutter Engine from 795db50e7453 to 3426cb827efb (9 revisions) (flutter/flutter#127738) 2023-05-27 [email protected] Updated the `ToggleButtons` API doc to link to `SegmentedButton` (flutter/flutter#127021) 2023-05-26 [email protected] Remove more `test_api/src` imports (flutter/flutter#127716) 2023-05-26 [email protected] Move shared inline widget logic to `RenderInlineWidgetContainerDefaults` (flutter/flutter#127308) 2023-05-26 [email protected] Roll Flutter Engine from 3b5b5fc96b8f to 795db50e7453 (1 revision) (flutter/flutter#127720) 2023-05-26 [email protected] Update collection-fors to prefer final (as per updated `prefer_final_in_for_each`) (flutter/flutter#127511) 2023-05-26 [email protected] Roll Flutter Engine from eed12f36f595 to 3b5b5fc96b8f (1 revision) (flutter/flutter#127713) 2023-05-26 [email protected] Remove references to deprecated `ThemeData.primaryColorBrightness` (flutter/flutter#127238) 2023-05-26 [email protected] TwoDimensional scrolling foundation (flutter/flutter#125437) 2023-05-26 [email protected] Roll Flutter Engine from 858d9753453c to eed12f36f595 (2 revisions) (flutter/flutter#127702) 2023-05-26 [email protected] Remove button announcement for `MenuItemButton` and `SubmenuButton` (flutter/flutter#127620) 2023-05-26 [email protected] Reland "Update labeler action wildcards #127524" (flutter/flutter#127690) 2023-05-26 [email protected] Revert "Log all lines from ios-deploy (#127502)" (flutter/flutter#127684) 2023-05-26 [email protected] Roll Flutter Engine from ec7b0ae3599f to 858d9753453c (2 revisions) (flutter/flutter#127700) 2023-05-26 [email protected] Add M3 date range picker tests and fix header background theme color (flutter/flutter#127662) 2023-05-26 [email protected] Support minifcation for apps that depend on AGP 8 and integration_test (flutter/flutter#127628) 2023-05-26 [email protected] Bump Snippet version (flutter/flutter#127688) 2023-05-26 [email protected] [Linux] Use up_client_get_devices2 when possible (flutter/flutter#127699) 2023-05-26 [email protected] Roll Flutter Engine from 84f2fc16e55d to ec7b0ae3599f (3 revisions) (flutter/flutter#127698) 2023-05-26 [email protected] Fix `TextField` error in production environment because it wrongly uses ancestor render boxes (flutter/flutter#126324) 2023-05-26 [email protected] Interactive viewer doesn't appear to respect the trackpadScrollCausesScale parameter (flutter/flutter#127114) 2023-05-26 [email protected] Remove release timeline (flutter/flutter#127685) 2023-05-26 [email protected] Manual roll Flutter Engine from 8573f3b63a1f to 84f2fc16e55d (7 revisions) (flutter/flutter#127676) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
InlineWidgetContainerDefaultsfor deduping inline widget codeWidgetSpan.extractFromInlineSpanfor extractingWidgetSpans and automatically applying text scaling (at widget level)TextPainter.inlinePlaceholderScales. I'm going to deprecate thescaleargument inTextPainter.addPlaceholdernext, as scaling is now done at the widget level.PlaceholderSpandirectly (unfortunately we can't removePlaceholderSpanwithout moving RenderEditable and RenderParagraph to the widgets library).Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.