This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed
lib/web_ui/lib/src/engine Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,10 @@ class HtmlViewEmbedder {
143
143
}
144
144
145
145
void _compositeWithParams (int viewId, EmbeddedViewParams params) {
146
+ // Ensure platform view with `viewId` is injected into the `rasterizer.view`
147
+ // before rendering its shadow DOM `slot`.
148
+ rasterizer.view.platformViewMessageHandler.injectPlatformView (viewId);
149
+
146
150
// If we haven't seen this viewId yet, cache it for clips/transforms.
147
151
final ViewClipChain clipChain = _viewClipChains.putIfAbsent (viewId, () {
148
152
return ViewClipChain (view: createPlatformViewSlot (viewId));
Original file line number Diff line number Diff line change 3
3
// found in the LICENSE file.
4
4
5
5
import '../dom.dart' ;
6
+ import '../platform_dispatcher.dart' ;
6
7
import '../platform_views/slots.dart' ;
8
+ import '../window.dart' ;
7
9
import 'surface.dart' ;
8
10
9
11
/// A surface containing a platform view, which is an HTML element.
@@ -18,6 +20,11 @@ class PersistedPlatformView extends PersistedLeafSurface {
18
20
19
21
@override
20
22
DomElement createElement () {
23
+ // Ensure platform view with `viewId` is injected into the `implicitView`
24
+ // before rendering its shadow DOM `slot`.
25
+ final EngineFlutterView implicitView = EnginePlatformDispatcher .instance.implicitView! ;
26
+ implicitView.platformViewMessageHandler.injectPlatformView (viewId);
27
+
21
28
return createPlatformViewSlot (viewId);
22
29
}
23
30
Original file line number Diff line number Diff line change @@ -65,6 +65,11 @@ class PlatformViewManager {
65
65
return _contents.containsKey (viewId);
66
66
}
67
67
68
+ /// Returns the pre-rendered contents of [viewId] , to inject them into the DOM.
69
+ DomElement getContents (int viewId) {
70
+ return _contents[viewId]! ;
71
+ }
72
+
68
73
/// Returns the HTML element created by a registered factory for [viewId] .
69
74
///
70
75
/// Throws an [AssertionError] if [viewId] hasn't been rendered before.
Original file line number Diff line number Diff line change @@ -88,16 +88,27 @@ class PlatformViewMessageHandler {
88
88
return ;
89
89
}
90
90
91
- final DomElement content = _contentManager.renderContent (
91
+ // Ensure the DomElement of the view is *created*, so programmers can
92
+ // access it through `_contentManager.getViewById` (maybe not the DOM!).
93
+ _contentManager.renderContent (
92
94
platformViewType,
93
95
platformViewId,
94
96
params,
95
97
);
96
98
99
+ callback (_codec.encodeSuccessEnvelope (null ));
100
+ }
101
+
102
+ /// Injects a platform view with [viewId] into this handler's `platformViewsContainer` .
103
+ void injectPlatformView (int viewId) {
97
104
// For now, we don't need anything fancier. If needed, this can be converted
98
105
// to a PlatformViewStrategy class for each web-renderer backend?
99
- _platformViewsContainer.append (content);
100
- callback (_codec.encodeSuccessEnvelope (null ));
106
+ final DomElement pv = _contentManager.getContents (viewId);
107
+ // If pv is a descendant of _platformViewsContainer -> noop
108
+ if (_platformViewsContainer.contains (pv)) {
109
+ return ;
110
+ }
111
+ _platformViewsContainer.append (pv);
101
112
}
102
113
103
114
/// Handle a `dispose` Platform View message.
You can’t perform that action at this time.
0 commit comments