-
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
Changes from 6 commits
417f2a3
3ebd407
da4b57e
c9b0e31
a7085ac
3d0894a
0363a96
62c14d9
ffd5037
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. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.