Skip to content

Commit 8d075fb

Browse files
committed
Stop configuring the max width and height in YogaUIView
These attributes only cause us pain. In particular they aren't necessary to pass any of our layout tests, and by removing them I can fix a layout bug. Note that on Android we do not use these attributes, so this brings the two platforms closer together. Closes: #2753
1 parent a62bee1 commit 8d075fb

12 files changed

+67
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Fixed:
1313
- Don't measure the height of `RedwoodUIView` as zero when measured with `sizeThatFits()` or `intrinsicContentSize()`. We had been using `UIStackView` which doesn't support these functions.
1414
- Correctly signal `RedwoodUIView` size changes of to callers who measure it with `intrinsicContentSize()`.
1515
- The Redwood Gradle plugin is now compatible with Gradle 9.1.
16+
- Don't incorrectly size items to 0 when using the `Flex()` modifier on a `Wrap` container.
1617

1718

1819
## [0.18.0] - 2025-08-01
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,43 @@ abstract class AbstractFlexContainerTest<T : Any> {
10891089

10901090
snapshotter(row.value).snapshot()
10911091
}
1092+
1093+
/**
1094+
* We had a bug where putting `flex(1.0)` on a child of a column with `height(Constraint.Wrap)`
1095+
* would cause that child to get a height of 0.
1096+
*
1097+
* https://github.com/cashapp/redwood/issues/2753
1098+
*/
1099+
@Test
1100+
fun testFlexOnChildOfWrappingColumn() {
1101+
val root = row().apply {
1102+
width(Constraint.Fill)
1103+
height(Constraint.Fill)
1104+
}
1105+
1106+
val fixedSize = row().apply {
1107+
width(Constraint.Fill)
1108+
height(Constraint.Fill)
1109+
modifier = SizeImpl(width = 300.dp, height = 500.dp)
1110+
}.also {
1111+
root.children.insert(0, it)
1112+
}
1113+
1114+
val column = column().apply {
1115+
width(Constraint.Fill)
1116+
}.also {
1117+
fixedSize.children.insert(0, it)
1118+
}
1119+
1120+
widgetFactory.text("hello").apply {
1121+
modifier = FlexImpl(1.0)
1122+
bgColor(Blue)
1123+
}.also {
1124+
column.children.insert(0, it)
1125+
}
1126+
1127+
snapshotter(root.value).snapshot()
1128+
}
10921129
}
10931130

10941131
interface TestFlexContainer<T : Any> :
Lines changed: 3 additions & 0 deletions
Loading

redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/YogaUIView.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,15 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel
9494
override fun intrinsicContentSize(): CValue<CGSize> {
9595
return calculateLayout(
9696
width = fillWidth.toYogaWithWidthConstraint(),
97-
maxWidth = fillWidth.toYoga(),
9897
height = fillHeight.toYogaWithWidthConstraint(),
99-
maxHeight = fillHeight.toYoga(),
10098
)
10199
}
102100

103101
override fun sizeThatFits(size: CValue<CGSize>): CValue<CGSize> {
104102
return size.useContents<CGSize, CValue<CGSize>> {
105103
calculateLayout(
106104
width = width.toYogaWithWidthConstraint(),
107-
maxWidth = width.toYoga(),
108105
height = height.toYogaWithHeightConstraint(),
109-
maxHeight = height.toYoga(),
110106
)
111107
}
112108
}
@@ -160,14 +156,12 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel
160156

161157
private fun calculateLayout(
162158
width: Float = Size.UNDEFINED,
163-
maxWidth: Float = Size.UNDEFINED,
164159
height: Float = Size.UNDEFINED,
165-
maxHeight: Float = Size.UNDEFINED,
166160
): CValue<CGSize> {
167161
rootNode.requestedWidth = width
168-
rootNode.requestedMaxWidth = maxWidth
162+
rootNode.requestedMaxWidth = Size.UNDEFINED
169163
rootNode.requestedHeight = height
170-
rootNode.requestedMaxHeight = maxHeight
164+
rootNode.requestedMaxHeight = Size.UNDEFINED
171165

172166
rootNode.measureOnly(Size.UNDEFINED, Size.UNDEFINED)
173167

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)