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] Provide convenient default factories for platform views #43828
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44b63ca
[web] Provide convenient default factories for platform views
mdebbar 7c2f6f7
Merge branch 'main' into default_factories
mdebbar 3d183ae
move view types to dart:ui_web
mdebbar 44ffc05
remove unnecessary extension
mdebbar f71dbab
Merge branch 'main' into default_factories
mdebbar ad3774e
make constants into statics on PlatformViewRegistry
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
Next
Next commit
[web] Provide convenient default factories for platform views
- Loading branch information
commit 44b63ca0d31ecc6eafcb8a7c86e57dc2a3dd2aad
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
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ import '../embedder.dart'; | |||
| import '../util.dart'; | ||||
| import 'slots.dart'; | ||||
|
|
||||
| // Keep these values in sync with the ones used in the framework's `HtmlElementView`. | ||||
| const String _kDefaultVisibleViewType = '_default_document_create_element_visible'; | ||||
| const String _kDefaultInvisibleViewType = '_default_document_create_element_invisible'; | ||||
|
|
||||
| /// This class handles the lifecycle of Platform Views in the DOM of a Flutter Web App. | ||||
| /// | ||||
| /// There are three important parts of Platform Views. This class manages two of | ||||
|
|
@@ -25,6 +29,19 @@ import 'slots.dart'; | |||
| /// This class keeps a registry of `factories`, `contents` so the framework can | ||||
| /// CRUD Platform Views as needed, regardless of the rendering backend. | ||||
| class PlatformViewManager { | ||||
| PlatformViewManager() { | ||||
| // Register some default factories. | ||||
| registerFactory( | ||||
| _kDefaultVisibleViewType, | ||||
| _defaultFactory, | ||||
| ); | ||||
| registerFactory( | ||||
| _kDefaultInvisibleViewType, | ||||
| _defaultFactory, | ||||
| isVisible: false, | ||||
| ); | ||||
| } | ||||
|
|
||||
| // The factory functions, indexed by the viewType | ||||
| final Map<String, Function> _factories = <String, Function>{}; | ||||
|
|
||||
|
|
@@ -223,3 +240,18 @@ class PlatformViewManager { | |||
| return result; | ||||
| } | ||||
| } | ||||
|
|
||||
| DomElement _defaultFactory( | ||||
| int viewId, { | ||||
| Object? params, | ||||
| }) { | ||||
| params!; | ||||
| params as _DefaultFactoryParams; | ||||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| return domDocument.createElement(params.tagName); | ||||
| } | ||||
|
|
||||
| typedef _DefaultFactoryParams = Map<Object?, Object?>; | ||||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| extension on _DefaultFactoryParams { | ||||
|
||||
| extension JsonExtensions on Map<dynamic, dynamic> { |
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
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.