Skip to content

Commit

Permalink
Adding support for the Height Modifier in ComposeUiBox (#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-cortes authored Nov 25, 2024
1 parent 0536ccf commit 6585a4c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,6 +68,7 @@ internal data class BoxChildLayoutInfo(
val alignment: Alignment,
val matchParentWidth: Boolean,
val matchParentHeight: Boolean,
val requestedHeight: Dp?
)

@PublishedApi
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +86,7 @@ internal class ComposeUiBox(
var alignment = alignment
var matchParentWidth = matchParentWidth
var matchParentHeight = matchParentHeight
var requestedHeight: Dp? = null

forEachScoped { childModifier ->
when (childModifier) {
Expand All @@ -109,7 +111,7 @@ internal class ComposeUiBox(
}

is Height -> {
// TODO
requestedHeight = childModifier.height.toDp()
}

is Size -> {
Expand All @@ -134,6 +136,7 @@ internal class ComposeUiBox(
alignment = alignment,
matchParentWidth = matchParentWidth,
matchParentHeight = matchParentHeight,
requestedHeight = requestedHeight,
)
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6585a4c

Please sign in to comment.