This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Support flutterViewId in platform view messages
#46891
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb01df8
[web] Support flutterViewId in platform view messages
mdebbar 116a716
utils for extracting flutter view id
mdebbar 54306b7
Merge branch 'main' into pv_view_id
mdebbar d637eee
platformViewId, platformViewType, viewId
mdebbar 40c7cb8
Merge branch 'main' into pv_view_id
mdebbar c98fde8
legacy tests
mdebbar 582f2c7
some cleanup
mdebbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ class PlatformViewMessageHandler { | |
|
|
||
| /// Handle a `create` Platform View message. | ||
| /// | ||
| /// This will attempt to render the `contents` and of a Platform View, if its | ||
| /// This will attempt to render the `contents` of a Platform View, if its | ||
| /// `viewType` has been registered previously. | ||
| /// | ||
| /// (See [PlatformViewManager.registerFactory] for more details.) | ||
|
|
@@ -63,37 +63,34 @@ class PlatformViewMessageHandler { | |
| /// If all goes well, this function will `callback` with an empty success envelope. | ||
| /// In case of error, this will `callback` with an error envelope describing the error. | ||
| void _createPlatformView( | ||
| MethodCall methodCall, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final Map<dynamic, dynamic> args = methodCall.arguments as Map<dynamic, dynamic>; | ||
| final int viewId = args.readInt('id'); | ||
| final String viewType = args.readString('viewType'); | ||
| final Object? params = args['params']; | ||
|
|
||
| if (!_contentManager.knowsViewType(viewType)) { | ||
| _PlatformMessageResponseCallback callback, { | ||
| required int platformViewId, | ||
| required String platformViewType, | ||
| required Object? params, | ||
| }) { | ||
| if (!_contentManager.knowsViewType(platformViewType)) { | ||
| callback(_codec.encodeErrorEnvelope( | ||
| code: 'unregistered_view_type', | ||
| message: 'A HtmlElementView widget is trying to create a platform view ' | ||
| 'with an unregistered type: <$viewType>.', | ||
| 'with an unregistered type: <$platformViewType>.', | ||
| details: 'If you are the author of the PlatformView, make sure ' | ||
| '`registerViewFactory` is invoked.', | ||
| )); | ||
| return; | ||
| } | ||
|
|
||
| if (_contentManager.knowsViewId(viewId)) { | ||
| if (_contentManager.knowsViewId(platformViewId)) { | ||
| callback(_codec.encodeErrorEnvelope( | ||
| code: 'recreating_view', | ||
| message: 'trying to create an already created view', | ||
| details: 'view id: $viewId', | ||
| details: 'view id: $platformViewId', | ||
| )); | ||
| return; | ||
| } | ||
|
|
||
| final DomElement content = _contentManager.renderContent( | ||
| viewType, | ||
| viewId, | ||
| platformViewType, | ||
| platformViewId, | ||
| params, | ||
| ); | ||
|
|
||
|
|
@@ -106,42 +103,75 @@ class PlatformViewMessageHandler { | |
| /// Handle a `dispose` Platform View message. | ||
| /// | ||
| /// This will clear the cached information that the framework has about a given | ||
| /// `viewId`, through the [_contentManager]. | ||
| /// `platformViewId`, through the [_contentManager]. | ||
| /// | ||
| /// Once that's done, the dispose call is delegated to the [_disposeHandler] | ||
| /// function, so the active rendering backend can dispose of whatever resources | ||
| /// it needed to get ahold of. | ||
| /// | ||
| /// This function should always `callback` with an empty success envelope. | ||
| void _disposePlatformView( | ||
| MethodCall methodCall, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final int viewId = methodCall.arguments as int; | ||
|
|
||
| _PlatformMessageResponseCallback callback, { | ||
| required int platformViewId, | ||
| }) { | ||
| // The contentManager removes the slot and the contents from its internal | ||
| // cache, and the DOM. | ||
| _contentManager.clearPlatformView(viewId); | ||
| _contentManager.clearPlatformView(platformViewId); | ||
|
|
||
| callback(_codec.encodeSuccessEnvelope(null)); | ||
| } | ||
|
|
||
| /// Handles legacy PlatformViewCalls that don't contain a Flutter View ID. | ||
| /// | ||
| /// This is transitional code to support the old platform view channel. As | ||
| /// soon as the framework code is updated to send the Flutter View ID, this | ||
| /// method can be removed. | ||
| void handleLegacyPlatformViewCall( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally forgot about this method. Good repurposing though!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must've been looking at an individual commit from the PR 🙂 This method is new. |
||
| String method, | ||
| dynamic arguments, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| switch (method) { | ||
| case 'create': | ||
| arguments as Map<dynamic, dynamic>; | ||
| _createPlatformView( | ||
| callback, | ||
| platformViewId: arguments.readInt('id'), | ||
| platformViewType: arguments.readString('viewType'), | ||
| params: arguments['params'], | ||
| ); | ||
| return; | ||
| case 'dispose': | ||
| _disposePlatformView(callback, platformViewId: arguments as int); | ||
| return; | ||
| } | ||
| callback(null); | ||
| } | ||
|
|
||
| /// Handles a PlatformViewCall to the `flutter/platform_views` channel. | ||
| /// | ||
| /// This method handles two possible messages: | ||
| /// * `create`: See [_createPlatformView] | ||
| /// * `dispose`: See [_disposePlatformView] | ||
| void handlePlatformViewCall( | ||
| ByteData? data, | ||
| String method, | ||
| Map<dynamic, dynamic> arguments, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final MethodCall decoded = _codec.decodeMethodCall(data); | ||
| switch (decoded.method) { | ||
| switch (method) { | ||
| case 'create': | ||
| _createPlatformView(decoded, callback); | ||
| _createPlatformView( | ||
| callback, | ||
| platformViewId: arguments.readInt('platformViewId'), | ||
| platformViewType: arguments.readString('platformViewType'), | ||
| params: arguments['params'], | ||
| ); | ||
| return; | ||
| case 'dispose': | ||
| _disposePlatformView(decoded, callback); | ||
| _disposePlatformView( | ||
| callback, | ||
| platformViewId: arguments.readInt('platformViewId'), | ||
| ); | ||
| return; | ||
| } | ||
| callback(null); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.