diff --git a/CHANGELOG.md b/CHANGELOG.md index 58444fabc1..60e88cfeb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Changed: Fixed: - Fix inconsistency in margin application between `ComposeUiBox` and `ViewBox`. +- Add support for the Height modifier in `ComposeUiBox`. ## [0.16.0] - 2024-11-19 diff --git a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/Box.kt b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/Box.kt index a3d6b8aebc..7349ff5e64 100644 --- a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/Box.kt +++ b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/Box.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.layout.MeasureResult import androidx.compose.ui.layout.MeasureScope import androidx.compose.ui.layout.Placeable import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.util.fastForEachIndexed @@ -67,6 +68,7 @@ internal data class BoxChildLayoutInfo( val alignment: Alignment, val matchParentWidth: Boolean, val matchParentHeight: Boolean, + val requestedHeight: Dp? ) @PublishedApi @@ -109,6 +111,11 @@ internal data class BoxMeasurePolicy( minHeight = if (boxHeight != Constraints.Infinity) boxHeight else 0, maxHeight = boxHeight, ) + } else if (layoutInfo.requestedHeight != null) { + childConstraints = childConstraints.copy( + minHeight = layoutInfo.requestedHeight.toPx().toInt(), + maxHeight = layoutInfo.requestedHeight.toPx().toInt(), + ) } val placeable = measurable.measure(childConstraints) placeables[index] = placeable diff --git a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiBox.kt b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiBox.kt index 1bb3e8b3a6..4c3aaecd18 100644 --- a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiBox.kt +++ b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiBox.kt @@ -31,6 +31,7 @@ import androidx.compose.ui.BiasAlignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp import androidx.compose.ui.util.fastMap import app.cash.redwood.Modifier as RedwoodModifier import app.cash.redwood.layout.api.Constraint @@ -85,6 +86,7 @@ internal class ComposeUiBox( var alignment = alignment var matchParentWidth = matchParentWidth var matchParentHeight = matchParentHeight + var requestedHeight: Dp? = null forEachScoped { childModifier -> when (childModifier) { @@ -109,7 +111,7 @@ internal class ComposeUiBox( } is Height -> { - // TODO + requestedHeight = childModifier.height.toDp() } is Size -> { @@ -134,6 +136,7 @@ internal class ComposeUiBox( alignment = alignment, matchParentWidth = matchParentWidth, matchParentHeight = matchParentHeight, + requestedHeight = requestedHeight, ) } diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_RTL_testChildExplicitHeight.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_RTL_testChildExplicitHeight.png index 2ce963b407..f2d827a52c 100644 --- a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_RTL_testChildExplicitHeight.png +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_RTL_testChildExplicitHeight.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3562b9122ec22acaf45b5a9ec6188bc4707ffac244b0395fae759dfa19dcee34 -size 5581 +oid sha256:0e5072fc1009dc442e8667845dbc73483603a21baa2b75ca70d2d7cb3b70172b +size 5600 diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_testChildExplicitHeight.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_testChildExplicitHeight.png index d9487ec055..833331ca10 100644 --- a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_testChildExplicitHeight.png +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiBoxTest_testChildExplicitHeight.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4c3130a3fc0e8428540637aecc4d76c8fcadc9fe821877ca4dab029ada222250 -size 5588 +oid sha256:8fb7ce8abe4210ff3124fd8359a96c38ae540335227e66b322ba64853e3ebea6 +size 5609