Skip to content

Commit

Permalink
Properly measure Box children (#2398)
Browse files Browse the repository at this point in the history
The Kotlin syntax I was using was not working. I can't
say why.

Closes: #2394
  • Loading branch information
squarejesse authored Oct 23, 2024
1 parent 5345799 commit 231b244
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Fixed:
- Fix a layout bug where children of fixed-with `Row` containers were assigned the wrong width.
- Fix inconsistencies between iOS and Android for `Column` and `Row` layouts.
- Correctly update the layout when a Box's child's modifiers are removed.
- Fix a layout bug where children of `Box` containers were not measured properly.

Breaking:
- Replace `CodeListener` with new functions in `RedwoodView`. This puts the loading/error/ready state with the UI that displays that state.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,36 @@ abstract class AbstractBoxTest<T : Any> {
b.text("BBB_v2")
snapshotter.snapshot("v2")
}

@Test
fun testChildExplicitHeight() {
val container = box()
.apply {
width(Constraint.Fill)
height(Constraint.Fill)
horizontalAlignment(CrossAxisAlignment.Stretch)
verticalAlignment(CrossAxisAlignment.Center)
}
val snapshotter = snapshotter(container.value)

val box = box()
.apply {
modifier = MarginImpl(all = 24.dp)
width(Constraint.Fill)
height(Constraint.Wrap)
horizontalAlignment(CrossAxisAlignment.Stretch)
verticalAlignment(CrossAxisAlignment.Center)
}
.also { container.children.insert(0, it) }

val a = widgetFactory.color().apply {
modifier = HeightImpl(100.dp)
}.also { box.children.insert(0, it) }

val b = widgetFactory.text(
text = "foreground",
).also { box.children.insert(1, it) }

snapshotter.snapshot()
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,22 @@ internal fun CGSizeMake(

/** Returns the smallest size that wraps both [a] and [b]. */
internal fun maxEachDimension(a: CValue<CGSize>, b: CValue<CGSize>): CValue<CGSize> {
return [email protected] {
[email protected] {
CGSizeMake(
maxOf(a@width, b@width),
maxOf(a@height, b@height),
)
}
val aWidth: CGFloat
val aHeight: CGFloat
a.useContents {
aWidth = width
aHeight = height
}
val bWidth: CGFloat
val bHeight: CGFloat
b.useContents {
bWidth = width
bHeight = height
}
return CGSizeMake(
maxOf(aWidth, bWidth),
maxOf(aHeight, bHeight),
)
}

/** Returns a margin that uses the largest of [a] and [b] for each side. */
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 231b244

Please sign in to comment.