-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[web] Send flutterViewId with platform view messages
#136548
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
ditman
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.
Minor comments, but in general LGTM!
(this can't land until the engine version does, though, since this is using new message argument names that are currently not understood by the engine)
| PlatformViewCreationParams params, | ||
| int viewId, |
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 isn't viewId part of the PlatformViewCreationParams? (This would be easy to change anyway)
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.
PlatformViewLink and PlatformViewCreationParams are used by all platforms and I didn't want to step on their stuff. I also want to hear from @goderbauer about how other platforms are going to deal with 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.
I didn't want to step on their stuff.
It's our stuff. We own this all together. :)
Adding the viewId to PlatformViewCreationParams sounds reasonable to me. I imagine other platforms will likely also need to know what FlutterView a PlatformView is associated with. @cbracken @loic-sharma have you thought about this in the context of your Desktop Platform view 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.
One thing to note, though: A PlatformView could move from one view to another. When scrolling through this PR I didn't see anything that would update the view ID associated with the controller when this happens?
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.
A PlatformView could move from one view to another.
Hm, that's an interesting case. In the web at least, since we'd need to move the actual DOM Content for platform_view (because each view has its own DOM shadow root), it'd be equivalent to destroying the view and recreating it from the factory elsewhere (in most cases).
I'm not sure how the framework/engine handles this case.
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 hadn't given this much thought I terms of desktop platform views but agreed we'll likely want this for desktop as well. Thanks for cc'ing, will take a look.
| PlatformViewCreationParams params, | ||
| int viewId, |
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 didn't want to step on their stuff.
It's our stuff. We own this all together. :)
Adding the viewId to PlatformViewCreationParams sounds reasonable to me. I imagine other platforms will likely also need to know what FlutterView a PlatformView is associated with. @cbracken @loic-sharma have you thought about this in the context of your Desktop Platform view work.
| PlatformViewCreationParams params, | ||
| int viewId, |
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.
One thing to note, though: A PlatformView could move from one view to another. When scrolling through this PR I didn't see anything that would update the view ID associated with the controller when this happens?
| import 'package:flutter/widgets.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| extension WrapperlessWidgetTester on WidgetTester { |
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 would just define this as a helper method until we're ready to actually implement this on WidgetTester itself)
|
Wow, thanks for adding support for moving the flutter view! The testing seems to be an analyzer issue:
|
| 'platformViewId': platformViewId, | ||
| 'viewId': flutterViewId, | ||
| }; | ||
| await SystemChannels.platform_views.invokeMethod<void>('moveToFlutterView', args); |
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.
| await SystemChannels.platform_views.invokeMethod<void>('moveToFlutterView', args); | |
| await SystemChannels.platform_views.invokeMethod<void>('move', args); |
👍 I'd call this move just to keep the same brevity of the create/dispose methods, but I don't have a strong opinion.
|
I'm still working on tests.. my latest commit broke some tests. Here's what I think so far: in tests, platform view creation happens synchronously in Note: The reason for moving platform view creation (or controller creation, really) from |
Ahhh, tricky tricky :/ |
| Future<void> create({Size? size, Offset? position}) async {} | ||
|
|
||
| /// Moves the platform view to a new [FlutterView]. | ||
| Future<void> moveToFlutterView(int flutterViewId) 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.
Could we update the PlatformViewController.viewId documentation on lines 1451-1457 to clarify that identifier is for the platform view (instead of a Flutter view)?
|
Missed this ping last week. Apologies. Instead of moving it from |
|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
(triage): @mdebbar said this is still on his radar in the next few weeks. |
|
Attempting to look at it from 30000 feet: Can |
|
Update: this PR may become superseded by flutter/engine#48960 |
This PR defers the injection of the contents of a Platform View into the DOM of the page, until the Platform View is really needed by a renderer. This effectively means that a `platformView` will be injected into the DOM the first time that its `slot` is injected into the Shadow DOM of the Flutter web app. This makes passing a `(flutter)ViewId` parameter from the framework unnecessary, even in a multi-view app. The only cases in which this change might be breaking is those where an app tries to locate the just-created Platform View by looking into the DOM from the [`onPlatformViewCreated` callback](https://api.flutter.dev/flutter/widgets/HtmlElementView/onPlatformViewCreated.html). In those cases, [a fix like this](flutter/packages#5660) is needed (use the **only [documented way](https://api.flutter.dev/flutter/dart-ui_web/PlatformViewRegistry/getViewById.html)** to obtain the Platform View contents from its `viewId`) ## Issues Fixes flutter/flutter#137287 Closes flutter/flutter#136548 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This PR prepares web platform views for the multi-view world.
Depends on flutter/engine#46891
Part of #137287