Skip to content

Commit

Permalink
Fix zero size layout in iOS interop (#1194)
Browse files Browse the repository at this point in the history
## Proposed Changes

Regression after #1145 (more specific is -
156b2ee)
- it was replaced by a zero-size layout that prevented drawing anything
and might lead to crashes in native views due to a zero size.
Please note that before we had incorrect/inconsistent behavior - iOS
interop occupied max available space. This PR aligns behaviour with
[`AndroidView`](https://github.com/JetBrains/compose-multiplatform-core/blob/v1.6.0/compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/viewinterop/AndroidViewHolder.android.kt#L387)
and just
[`Box`](https://github.com/JetBrains/compose-multiplatform-core/blob/v1.6.0/compose/foundation/foundation-layout/src/commonMain/kotlin/androidx/compose/foundation/layout/Box.kt#L212-L214)

## Testing

Test: mpp demo, pages with interop

## Issues Fixed

Fixes JetBrains/compose-multiplatform#4447
  • Loading branch information
MatkovIvan committed Mar 14, 2024
1 parent 5c27720 commit 0b8d76d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ val ComposeAndNativeScroll = Screen.Example("ScrollDraggingTest") {
Spacer(Modifier.height(10.dp))
Text("UIKit:")
Box(modifier = Modifier.height(ItemsHeight.dp)) {
UIKitView(::makeScrollView, Modifier.height(ItemsHeight.dp))
UIKitView(::makeScrollView, Modifier.fillMaxSize())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.compose.ui.Modifier
internal fun EmptyLayout(modifier: Modifier) = Layout(
content = {},
modifier = modifier,
measurePolicy = { _, _ ->
layout(0, 0) {}
measurePolicy = { _, constraints ->
layout(constraints.minWidth, constraints.minHeight) {}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal fun OverlayLayout(modifier: Modifier, content: @Composable () -> Unit)
measurePolicy = { measurables, constraints ->
val placeables = measurables.map { it.measure(constraints) }
layout(
placeables.maxOfOrNull { it.width } ?: 0,
placeables.maxOfOrNull { it.height } ?: 0
placeables.maxOfOrNull { it.width } ?: constraints.minWidth,
placeables.maxOfOrNull { it.height } ?: constraints.minHeight
) {
placeables.forEach {
it.place(0, 0)
Expand Down

0 comments on commit 0b8d76d

Please sign in to comment.