-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Add dynamic view sizing for non-implicit views. #48541
Conversation
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.
Reviewing myself.
viewManager.onViewsChanged.listen((_) { | ||
invokeOnMetricsChanged(); | ||
}); |
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.
Do we want to auto-attach this here, or should we do it after the view has been created, through some registration method in the platform_dispatcher?
@@ -391,7 +391,7 @@ class CanvasKitRenderer implements Renderer { | |||
final Rasterizer rasterizer = | |||
_getRasterizerForView(view as EngineFlutterView); | |||
|
|||
rasterizer.draw((scene as LayerScene).layerTree); | |||
rasterizer.draw((scene as LayerScene).layerTree, size: size); |
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.
@harryterkelsen is there a way of testing this? Somehow asserting that the thing that was drawn matches the size of the incoming size
?
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.
IIRC the size is only used to size the output canvases before drawing to them, so if you wanted to test this then I think you should call draw
with an explicit size and then check that the bitmap created and the bitmaprenderer canvases are the same size as the size
that is passed in.
// The controller of the [onViewsChanged] stream. | ||
final StreamController<void> _onViewsChangedController = | ||
StreamController<void>.broadcast(); | ||
|
||
/// A stream of `void` events that will fire when a view is registered/unregistered. | ||
Stream<void> get onViewsChanged => _onViewsChangedController.stream; | ||
|
||
/// Should we create a different onViewResized stream? |
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 we propagate resize events from this class at all, or should these subscriptions live elsewhere?
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 we always re-render when there is a resize, then I don't think we need a stream for resize events. I would rather have resize trigger a re-render at a higher level in the engine/framework than at the Renderer level since it doesn't seem right to me for the Renderer to decide when to re-render. I think the Renderer should only perform Render requests and never initiate them.
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.
Responded to some questions in the PR. I think we should add a test showing a scene being rendered at different sizes in the CanvasKit tests.
5372b79
to
44a4b07
Compare
0ecdf36
to
a612de8
Compare
a612de8
to
a691ace
Compare
Dynamic View Sizing has relanded in the framework: Time to refresh this PR! |
This can be simplified SSSSSO much, it's embarrassing. I'm going to post the simpler version in a new PR so we can all easily laugh together 🤦 |
This is much better, closing: #50271 |
### Changes * Introduces a new `viewConstraints` JS configuration parameter to configure max/min width/height constraints for a view. Those can have the following values: * An integer `>= 0`: max/min size in pixels * `Infinity` (or `Number.POSITIVE_INFINITY`): (only for max values) -> **unconstrained**. * When any value is not set, it defaults to "tight to the current size". * See [Understanding constraints](https://docs.flutter.dev/ui/layout/constraints). * Computes the correct `physicalConstraints` of a view off of its `physicalSize` and its `viewConstraints` for the framework to use during layout. * When no constraints are passed, the current behavior is preserved: the default constraints are "tight" to the `physicalSize`. * Resizes the current view DOM when requested by the framework and updates its internal physicalSize, then continues with the render procedure. ### Example This is how we can configure a view to "take as much vertical space as needed": ```js flutterApp.addView({ viewConstraints: { minHeight: 0, maxHeight: Infinity, }, hostElement: ..., }); ``` ### TODO * Needs actual unit tests ### Issues * Fixes flutter/flutter#137444 * Closes #48541 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
### Changes * Introduces a new `viewConstraints` JS configuration parameter to configure max/min width/height constraints for a view. Those can have the following values: * An integer `>= 0`: max/min size in pixels * `Infinity` (or `Number.POSITIVE_INFINITY`): (only for max values) -> **unconstrained**. * When any value is not set, it defaults to "tight to the current size". * See [Understanding constraints](https://docs.flutter.dev/ui/layout/constraints). * Computes the correct `physicalConstraints` of a view off of its `physicalSize` and its `viewConstraints` for the framework to use during layout. * When no constraints are passed, the current behavior is preserved: the default constraints are "tight" to the `physicalSize`. * Resizes the current view DOM when requested by the framework and updates its internal physicalSize, then continues with the render procedure. ### Example This is how we can configure a view to "take as much vertical space as needed": ```js flutterApp.addView({ viewConstraints: { minHeight: 0, maxHeight: Infinity, }, hostElement: ..., }); ``` ### TODO * Needs actual unit tests ### Issues * Fixes flutter/flutter#137444 * Closes flutter#48541 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This PR
physicalConstraints
of a view off of itsphysicalSize
and theJSViewConstraints
passed by the user when creating a view.physicalSize
.-1
is a valid "max" constraint, and is interpreted asdouble.infinity
in Flutter.Size
of arender
call into therenderer
, so it doesn't have to rely in the (maybe outdated)physicalSize
of a view.onResize
event from a view into thedimensionsChanged
event from the Engine, so the framework knows it needs to repaint.TODO:
resizes
and not always that the app needs to render.Issues
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.