diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_both.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_both.png new file mode 100644 index 0000000000..21d3b5e65c --- /dev/null +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77d910e390037dff701db93fc859d94eb6372c1dff73a9ddbe43bf207b4561f7 +size 5200 diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_single.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_single.png new file mode 100644 index 0000000000..c8383cb1a6 --- /dev/null +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[LTR]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd3a40475d0beeec4241b721047fc3c12889cc12a67cb436bf321aec85479fc0 +size 4521 diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_both.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_both.png new file mode 100644 index 0000000000..4c80c8a344 --- /dev/null +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bbdb114d652f88923881f607aeb507539793572d5065731e359bc3add227024 +size 5153 diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_single.png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_single.png new file mode 100644 index 0000000000..b21cab8c71 --- /dev/null +++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testDynamicContainerSize[RTL]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:083a499212b8111350e57ae1c217cb52d14eeef8ee7bb15e1cfc8d45ed04d70c +size 4507 diff --git a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt index 03fbd0ba1d..b37f3e15bb 100644 --- a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt +++ b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt @@ -437,6 +437,60 @@ abstract class AbstractFlexContainerTest { verifySnapshot(container, "BCDE") } + @Test + fun testDynamicContainerSize() { + val parent = flexContainer(FlexDirection.Column).apply { + width(Constraint.Fill) + height(Constraint.Fill) + } + + parent.add( + flexContainer(FlexDirection.Column).apply { + modifier = GrowImpl(1.0) + width(Constraint.Fill) + mainAxisAlignment(MainAxisAlignment.SpaceBetween) + add( + widget( + "A", + GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.Start)), + ), + ) + add( + widget( + "B", + GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.End)), + ), + ) + }, + ) + + parent.add( + flexContainer(FlexDirection.Column).apply { + modifier = GrowImpl(1.0) + width(Constraint.Fill) + mainAxisAlignment(MainAxisAlignment.SpaceBetween) + add( + widget( + "C", + GrowImpl(1.0) + .then(CrossAxisAlignmentImpl(CrossAxisAlignment.Start)), + ), + ) + add( + widget( + "D", + GrowImpl(1.0).then(CrossAxisAlignmentImpl(CrossAxisAlignment.End)), + ), + ) + }, + ) + + verifySnapshot(parent, "both") + + parent.removeAt(1) + verifySnapshot(parent, "single") + } + /** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */ private fun assumeTrue(b: Boolean) { assertTrue(b) diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png new file mode 100644 index 0000000000..f3397b1794 --- /dev/null +++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b9a756eddfdc540f4b3780c965f0b5d92126a41d87aaf28cbe99f41e1ff8d79 +size 71109 diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.single.png b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.single.png new file mode 100644 index 0000000000..680502f40d --- /dev/null +++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d0b0322fa313b5a2e71c2a23ff1af419ca31aa0739230063ae77af0cbfdfd3e +size 67288 diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt index e16705cc3f..7e55183bec 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt @@ -168,8 +168,7 @@ internal class ViewFlexContainer( } private fun View.asNode(): Node { - val childNode = Node() - childNode.measureCallback = ViewMeasureCallback(this) - applyLayoutParams(childNode, layoutParams) - return childNode + return Node().apply { + measureCallback = ViewMeasureCallback(this@asNode) + } } diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt index 2a5ff354c4..763ba74875 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt @@ -21,10 +21,6 @@ internal class YogaLayout( ) : ViewGroup(context) { val rootNode = Node() - init { - applyLayoutParams(rootNode, layoutParams) - } - private fun applyLayout(node: Node, xOffset: Float, yOffset: Float) { val view = node.view if (view != null && view !== this) { @@ -71,6 +67,11 @@ internal class YogaLayout( } private fun calculateLayout(widthSpec: Int, heightSpec: Int) { + rootNode.requestedWidth = Size.Undefined + rootNode.requestedMaxWidth = Size.Undefined + rootNode.requestedHeight = Size.Undefined + rootNode.requestedMaxHeight = Size.Undefined + val widthSize = MeasureSpec.getSize(widthSpec).toFloat() when (MeasureSpec.getMode(widthSpec)) { MeasureSpec.EXACTLY -> rootNode.requestedWidth = widthSize @@ -95,16 +96,3 @@ internal class YogaLayout( private val Node.view: View? get() = (measureCallback as ViewMeasureCallback?)?.view - -internal fun applyLayoutParams(node: Node, layoutParams: ViewGroup.LayoutParams?) { - if (layoutParams != null) { - val width = layoutParams.width - if (width >= 0) { - node.requestedWidth = width.toFloat() - } - val height = layoutParams.height - if (height >= 0) { - node.requestedHeight = height.toFloat() - } - } -} diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_both.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_both.png new file mode 100644 index 0000000000..7f3ca87b21 --- /dev/null +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:445b5e84c3d6342d15cb45bb0634775904a2112fbc592dc92ffb547c206a17b9 +size 5038 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_single.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_single.png new file mode 100644 index 0000000000..727937df6f --- /dev/null +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[LTR]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7ae0f67e98cc7c27e17b4953c9fffaef91a6e085676409824213540b26b9879 +size 4431 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_both.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_both.png new file mode 100644 index 0000000000..801ba837e2 --- /dev/null +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70326dd39f7da01639bce12bf7a7989514d7e7862e1cebca1fa57a2cb1f0901c +size 5015 diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_single.png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_single.png new file mode 100644 index 0000000000..7c6e68701b --- /dev/null +++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testDynamicContainerSize[RTL]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0752287d527e479efad0f29e745abeeb67eb9b6b84e8893a5bfaa02ac749c6c7 +size 4425 diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_both.png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_both.png new file mode 100644 index 0000000000..784d7fc152 --- /dev/null +++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57e6bb80bdab38226d042e9f722c4b0951a83ca348ef237b1b5e7e64d5770def +size 3836 diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_single.png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_single.png new file mode 100644 index 0000000000..784d7fc152 --- /dev/null +++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[LTR]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57e6bb80bdab38226d042e9f722c4b0951a83ca348ef237b1b5e7e64d5770def +size 3836 diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_both.png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_both.png new file mode 100644 index 0000000000..784d7fc152 --- /dev/null +++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57e6bb80bdab38226d042e9f722c4b0951a83ca348ef237b1b5e7e64d5770def +size 3836 diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_single.png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_single.png new file mode 100644 index 0000000000..784d7fc152 --- /dev/null +++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testDynamicContainerSize[RTL]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57e6bb80bdab38226d042e9f722c4b0951a83ca348ef237b1b5e7e64d5770def +size 3836 diff --git a/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_both.png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_both.png new file mode 100644 index 0000000000..ebb6a426ef --- /dev/null +++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdca08973fd5cbf55a12717a65eaa147bbfaff662cc7dca62bcae0f9d63a9859 +size 3837 diff --git a/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_single.png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_single.png new file mode 100644 index 0000000000..ebb6a426ef --- /dev/null +++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[LTR]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdca08973fd5cbf55a12717a65eaa147bbfaff662cc7dca62bcae0f9d63a9859 +size 3837 diff --git a/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_both.png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_both.png new file mode 100644 index 0000000000..ebb6a426ef --- /dev/null +++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_both.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdca08973fd5cbf55a12717a65eaa147bbfaff662cc7dca62bcae0f9d63a9859 +size 3837 diff --git a/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_single.png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_single.png new file mode 100644 index 0000000000..ebb6a426ef --- /dev/null +++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testDynamicContainerSize[RTL]_single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdca08973fd5cbf55a12717a65eaa147bbfaff662cc7dca62bcae0f9d63a9859 +size 3837