-
Notifications
You must be signed in to change notification settings - Fork 154
Fix initial Skiko popup positioning #3321
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
base: jb-main
Are you sure you want to change the base?
Changes from 5 commits
417f2a3
3ebd407
da4b57e
c9b0e31
a7085ac
3d0894a
0363a96
62c14d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import androidx.compose.runtime.InternalComposeApi | |
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.MutableState | ||
| import androidx.compose.runtime.currentCompositeKeyHashCode | ||
| import androidx.compose.runtime.derivedStateOf | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
|
|
@@ -471,10 +472,10 @@ private fun PopupLayout( | |
| content: @Composable () -> Unit | ||
| ) { | ||
| // Use a MutableState directly to avoid recomposing when the value changes | ||
| val parentBoundsInWindow: MutableState<IntRect> = remember { mutableStateOf(IntRect.Zero) } | ||
| // Use nullable as a marker to wait until the popup scene has a real parent anchor before | ||
| // composing its content. | ||
| val parentBoundsInWindow: MutableState<IntRect?> = remember { mutableStateOf(null) } | ||
| EmptyLayout(Modifier.onPlaced { childCoordinates -> | ||
| // This will be called before the popup measure policy is actually asked to calculate | ||
| // the popup's position, so it will never see the initial value of IntRect.Zero | ||
| childCoordinates.parentCoordinates?.let { | ||
| // Nodes which read layout coordinates (including, e.g., positionInWindow) in | ||
| // layout/placement get invalidated when these coordinates change | ||
|
|
@@ -492,6 +493,11 @@ private fun PopupLayout( | |
| layer.setKeyEventListener(onPreviewKeyEvent, onKeyEvent) | ||
| layer.setOutsidePointerEventListener(onOutsidePointerEvent) | ||
| layer.Content { | ||
| val canCalculatePosition by remember { | ||
| derivedStateOf { parentBoundsInWindow.value != null } | ||
| } | ||
| if (!canCalculatePosition) return@Content | ||
|
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. It seems it breaks "showing in the same frame" behavior. Test failures seems to be related
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. yes, wrote a comment about that: #3321 (comment) we need to choose which is preferred. 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.
|
||
|
|
||
| val platformInsets = properties.platformInsets | ||
| val containerSize = LocalWindowInfo.current.containerSize | ||
| val layoutDirection = LocalLayoutDirection.current | ||
|
|
@@ -541,7 +547,7 @@ private fun rememberPopupMeasurePolicy( | |
| containerSize: IntSize, | ||
| platformInsets: PlatformInsets, | ||
| layoutDirection: LayoutDirection, | ||
| parentBoundsInWindow: MutableState<IntRect> | ||
| parentBoundsInWindow: MutableState<IntRect?> | ||
| ) = remember( | ||
| layer, | ||
| popupPositionProvider, | ||
|
|
@@ -556,6 +562,7 @@ private fun rememberPopupMeasurePolicy( | |
| usePlatformDefaultWidth = properties.usePlatformDefaultWidth | ||
| ) { contentSize -> | ||
| val parentRectInWindow = parentBoundsInWindow.value | ||
| ?: return@ComposeSceneLayerMeasurePolicy IntOffset.Zero | ||
| val positionWithInsets = | ||
| positionWithInsets(platformInsets, containerSize) { sizeWithoutInsets -> | ||
| // Position provider works in coordinates without insets. | ||
|
|
||
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.
By checking the 100x100 size you're validating that the popup isn't composed until the dialog is rendered. This is the (new) behavior, but it's not a required behavior, so we shouldn't check for it.
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 test wants to verify that a dialog/window with a popup accomodates the popup's size when being shown. The PR seems to break 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 see, got it. I didn't realize that some popups are still part of the scene they are shown from and can be shown immediately. We could distinguish this by introducing a flag in
ComposeSceneContext, likelayersShareCurrentScene, do you see a problem with this approach?Uh oh!
There was an error while loading. Please reload this page.
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.
Can we do it without a flag?
I guess what I don't understand is how this PR breaks the existing functionality when the popup is in the same scene. It seems that if indeed
EmptyLayout(Modifier.onPlaced)is called before the popup measure policy, the popup should be shown immediately. What am I missing?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.
Yes. Scene is designed to hide this implementation detail.
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.
Flag is not needed. We can handle it all in Popup. For some reason I didn't realize it at first and imagined it more complicated. Alexander Maryanovsky (@m-sasha) thanks for pointing it out.