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
[skwasm] Fix platform view placement. #53845
Merged
auto-submit
merged 1 commit into
flutter:main
from
eyebrowsoffire:skwasm_platform_view_placement
Jul 12, 2024
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,7 @@ class EngineSceneView { | |
} | ||
} | ||
container ??= PlatformViewContainer(view.viewId); | ||
container.size = view.size; | ||
container.bounds = view.bounds; | ||
container.styling = view.styling; | ||
container.updateContents(); | ||
newContainers.add(container); | ||
|
@@ -281,7 +281,7 @@ final class PlatformViewContainer extends SliceContainer { | |
|
||
final int viewId; | ||
PlatformViewStyling? _styling; | ||
ui.Size? _size; | ||
ui.Rect? _bounds; | ||
bool _dirty = false; | ||
|
||
@override | ||
|
@@ -294,9 +294,9 @@ final class PlatformViewContainer extends SliceContainer { | |
} | ||
} | ||
|
||
set size(ui.Size size) { | ||
if (_size != size) { | ||
_size = size; | ||
set bounds(ui.Rect bounds) { | ||
if (_bounds != bounds) { | ||
_bounds = bounds; | ||
_dirty = true; | ||
} | ||
} | ||
|
@@ -305,23 +305,28 @@ final class PlatformViewContainer extends SliceContainer { | |
@override | ||
void updateContents() { | ||
assert(_styling != null); | ||
assert(_size != null); | ||
assert(_bounds != null); | ||
if (_dirty) { | ||
final DomCSSStyleDeclaration style = container.style; | ||
final double devicePixelRatio = EngineFlutterDisplay.instance.devicePixelRatio; | ||
final double logicalWidth = _size!.width / devicePixelRatio; | ||
final double logicalHeight = _size!.height / devicePixelRatio; | ||
final double logicalWidth = _bounds!.width / devicePixelRatio; | ||
final double logicalHeight = _bounds!.height / devicePixelRatio; | ||
style.width = '${logicalWidth}px'; | ||
style.height = '${logicalHeight}px'; | ||
style.position = 'absolute'; | ||
|
||
final ui.Offset? offset = _styling!.position.offset; | ||
final double logicalLeft = (offset?.dx ?? 0) / devicePixelRatio; | ||
final double logicalTop = (offset?.dy ?? 0) / devicePixelRatio; | ||
final PlatformViewPosition position = PlatformViewPosition.combine( | ||
_styling!.position, | ||
PlatformViewPosition.offset(_bounds!.topLeft), | ||
); | ||
|
||
final ui.Offset offset = position.offset ?? ui.Offset.zero; | ||
final double logicalLeft = offset.dx / devicePixelRatio; | ||
final double logicalTop = offset.dy / devicePixelRatio; | ||
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. Up to you, but local variable types are now optional. It might be good to take advantage of it in individual PRs so we don't have to do a huge type rewrite later. |
||
style.left = '${logicalLeft}px'; | ||
style.top = '${logicalTop}px'; | ||
|
||
final Matrix4? transform = _styling!.position.transform; | ||
final Matrix4? transform = position.transform; | ||
style.transform = transform != null ? float64ListToCssTransform3d(transform.storage) : ''; | ||
style.opacity = _styling!.opacity != 1.0 ? '${_styling!.opacity}' : ''; | ||
// TODO(jacksongardner): Implement clip styling for platform views | ||
|
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
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.
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.
Unable to comment on the internals of this class, so commenting here. Just a nit that we should probably put
transform
first andoffset
second in the order of fields, arguments, and various expressions that involve both because transform is applied first and offset is applied second. For example, if you have a transform layer and you doaddPlatformView(offset)
, you first apply the transform and then the offset. Unless I'm misunderstanding what these fields do.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.
This is an "either-or" class, where either the offset or the transform are specified but never both. If there is an offset and a transform that are combined, they just become a transform only (the offset is applied properly to the transform). As such, there is no ordering implied here within this class.