diff --git a/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt b/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt
index ec213e9e13..19500efb95 100644
--- a/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt
+++ b/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt
@@ -18,6 +18,7 @@ package com.example
import app.cash.redwood.Modifier
import app.cash.redwood.layout.api.CrossAxisAlignment
import app.cash.redwood.layout.api.MainAxisAlignment
+import app.cash.redwood.layout.modifier.Flex as FlexModifier
import app.cash.redwood.layout.modifier.Grow as GrowModifier
import app.cash.redwood.layout.modifier.Height as HeightModifier
import app.cash.redwood.layout.modifier.HorizontalAlignment as HorizontalAlignmentModifier
@@ -97,6 +98,12 @@ internal fun Node.applyModifier(parentModifier: Modifier, density: Density) {
requestedMinHeight = height
requestedMaxHeight = height
}
+ is FlexModifier -> {
+ val flex = childModifier.value.coerceAtLeast(0.0).toFloat()
+ flexGrow = flex
+ flexShrink = 1.0f
+ flexBasis = if (flex > 0) 0.0f else -1.0f
+ }
}
}
}
diff --git a/redwood-layout-compose/src/commonMain/kotlin/app/cash/redwood/layout/compose/LayoutScopes.kt b/redwood-layout-compose/src/commonMain/kotlin/app/cash/redwood/layout/compose/LayoutScopes.kt
index 222ea48b42..a8f2a903da 100644
--- a/redwood-layout-compose/src/commonMain/kotlin/app/cash/redwood/layout/compose/LayoutScopes.kt
+++ b/redwood-layout-compose/src/commonMain/kotlin/app/cash/redwood/layout/compose/LayoutScopes.kt
@@ -24,5 +24,10 @@ import app.cash.redwood.Modifier
* Call this in [ColumnScope] or [RowScope].
*/
@Stable
+@Deprecated(
+ message = "This extension function is obselete now that RowScope and " +
+ "ColumnScope support flex directly. Remove the import for this function.",
+ level = DeprecationLevel.ERROR,
+)
public fun Modifier.flex(`value`: Double): Modifier =
then(GrowImpl(`value`)).then(ShrinkImpl(`value`))
diff --git a/redwood-layout-compose/src/commonTest/kotlin/app/cash/redwood/layout/compose/LayoutScopesTest.kt b/redwood-layout-compose/src/commonTest/kotlin/app/cash/redwood/layout/compose/LayoutScopesTest.kt
deleted file mode 100644
index 006b1dbea2..0000000000
--- a/redwood-layout-compose/src/commonTest/kotlin/app/cash/redwood/layout/compose/LayoutScopesTest.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2023 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package app.cash.redwood.layout.compose
-
-import app.cash.redwood.Modifier
-import kotlin.test.Test
-import kotlin.test.assertEquals
-
-class LayoutScopesTest {
- @Test
- fun flexIsGrowAndShrink() {
- val flex = Modifier.flex(0.5)
- val components = flex.components()
- assertEquals(
- listOf(GrowImpl(0.5), ShrinkImpl(0.5)),
- components,
- )
- }
-
- private fun Modifier.components(): List {
- return buildList {
- this@components.forEach {
- add(it)
- }
- }
- }
-}
diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[LTR].png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[LTR].png
new file mode 100644
index 0000000000..ebda8aa974
--- /dev/null
+++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bf2c950e21c16f1ba234681f69a7c1f7597d21418efa3669d5f0823c90278f26
+size 10217
diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[RTL].png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[RTL].png
new file mode 100644
index 0000000000..787b543d36
--- /dev/null
+++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightEqually[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:47f6085e608f526972a4686d33190b56cea16883b822403f1ea170c6bef935f8
+size 10291
diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png
new file mode 100644
index 0000000000..a98bbd011e
--- /dev/null
+++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9bca3940fac5f97e68c4f739576dde64d481db472cc56aed60969df7dd5ddf13
+size 10240
diff --git a/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png
new file mode 100644
index 0000000000..f075c132dd
--- /dev/null
+++ b/redwood-layout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9f2ae8b6c781141c460143f3593e712c8f9e69817a536d3acb33f84b27b13d7f
+size 10154
diff --git a/redwood-layout-schema/redwood-api.xml b/redwood-layout-schema/redwood-api.xml
index bd571c9d8e..fac28ec74c 100644
--- a/redwood-layout-schema/redwood-api.xml
+++ b/redwood-layout-schema/redwood-api.xml
@@ -54,4 +54,7 @@
+
+
+
diff --git a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt
index 3a1e39624b..08cbb0a5ae 100644
--- a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt
+++ b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/modifiers.kt
@@ -91,3 +91,15 @@ public data class Size(
val width: Dp,
val height: Dp,
)
+
+/**
+ * This value acts as a weight for the width/height of a widget along the main axis.
+ *
+ * For instance, setting `flex(1.0)` on each widget in a layout will create equally sized widgets.
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/flex
+ */
+@Modifier(9, RowScope::class, ColumnScope::class)
+public data class Flex(
+ val value: Double,
+)
diff --git a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt
index 1e100e5742..1d483075c0 100644
--- a/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt
+++ b/redwood-layout-schema/src/main/kotlin/app/cash/redwood/layout/schema.kt
@@ -27,6 +27,7 @@ import app.cash.redwood.schema.Schema
// Next tag: 5
// Modifiers
+ Flex::class,
Grow::class,
Height::class,
HorizontalAlignment::class,
@@ -35,7 +36,7 @@ import app.cash.redwood.schema.Schema
Size::class,
VerticalAlignment::class,
Width::class,
- // Next tag: 9
+ // Next tag: 10
],
)
public interface RedwoodLayout
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 196f2f4c18..f4503275ea 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
@@ -19,9 +19,11 @@ import app.cash.redwood.Modifier
import app.cash.redwood.layout.api.Constraint
import app.cash.redwood.layout.api.CrossAxisAlignment
import app.cash.redwood.layout.api.MainAxisAlignment
+import app.cash.redwood.layout.modifier.Flex
import app.cash.redwood.layout.modifier.Grow
import app.cash.redwood.layout.modifier.Height
import app.cash.redwood.layout.modifier.HorizontalAlignment
+import app.cash.redwood.layout.modifier.Margin as MarginModifier
import app.cash.redwood.layout.modifier.Shrink
import app.cash.redwood.layout.modifier.Size
import app.cash.redwood.layout.modifier.VerticalAlignment
@@ -495,6 +497,30 @@ abstract class AbstractFlexContainerTest {
verifySnapshot(parent, "single")
}
+ @Test
+ fun testFlexDistributesWeightEqually() {
+ val container = flexContainer(FlexDirection.Row)
+ container.width(Constraint.Fill)
+ container.height(Constraint.Fill)
+ container.add(widget("REALLY LONG TEXT", FlexImpl(1.0)))
+ container.add(widget("SHORTER TEXT", FlexImpl(1.0)))
+ container.add(widget("A", FlexImpl(1.0)))
+ container.add(widget("LINE1\nLINE2\nLINE3", FlexImpl(1.0)))
+ verifySnapshot(container)
+ }
+
+ @Test
+ fun testFlexDistributesWeightUnequally() {
+ val container = flexContainer(FlexDirection.Row)
+ container.width(Constraint.Fill)
+ container.height(Constraint.Fill)
+ container.add(widget("REALLY LONG TEXT", FlexImpl(3.0)))
+ container.add(widget("SHORTER TEXT", FlexImpl(1.0)))
+ container.add(widget("A", FlexImpl(1.0)))
+ container.add(widget("LINE1\nLINE2\nLINE3", FlexImpl(1.0)))
+ verifySnapshot(container)
+ }
+
/** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */
private fun assumeTrue(b: Boolean) {
assertTrue(b)
@@ -550,15 +576,19 @@ private data class SizeImpl(
) : Size
private data class MarginImpl(
- override val margin: app.cash.redwood.ui.Margin,
-) : app.cash.redwood.layout.modifier.Margin {
+ override val margin: Margin,
+) : MarginModifier {
constructor(all: Dp = 0.dp) : this(Margin(all))
}
private data class GrowImpl(
- override val `value`: Double,
+ override val value: Double,
) : Grow
private data class ShrinkImpl(
- override val `value`: Double,
+ override val value: Double,
) : Shrink
+
+private data class FlexImpl(
+ override val value: Double,
+) : Flex
diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests.xcodeproj/xcshareddata/xcschemes/RedwoodLayoutUIViewTests.xcscheme b/redwood-layout-uiview/RedwoodLayoutUIViewTests.xcodeproj/xcshareddata/xcschemes/RedwoodLayoutUIViewTests.xcscheme
new file mode 100644
index 0000000000..b489a6b622
--- /dev/null
+++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests.xcodeproj/xcshareddata/xcschemes/RedwoodLayoutUIViewTests.xcscheme
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightEqually.1.png b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightEqually.1.png
new file mode 100644
index 0000000000..77873ba145
--- /dev/null
+++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightEqually.1.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:08702e97effc63a8329e2b0c1b2765ae8c2424a47a9ee2afd2e783c589055d1e
+size 73348
diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightUnequally.1.png b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightUnequally.1.png
new file mode 100644
index 0000000000..6ec11a11aa
--- /dev/null
+++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testFlexDistributesWeightUnequally.1.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4d89029ad74cdcddbd5dcb8ba78b8f573db455541847c28370ea6654adf445ec
+size 73097
diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[LTR].png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[LTR].png
new file mode 100644
index 0000000000..ebda8aa974
--- /dev/null
+++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bf2c950e21c16f1ba234681f69a7c1f7597d21418efa3669d5f0823c90278f26
+size 10217
diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[RTL].png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[RTL].png
new file mode 100644
index 0000000000..787b543d36
--- /dev/null
+++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightEqually[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:47f6085e608f526972a4686d33190b56cea16883b822403f1ea170c6bef935f8
+size 10291
diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png
new file mode 100644
index 0000000000..51ef899710
--- /dev/null
+++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:8211254756c6ef0608390d6ef17ff97f6994e17bed7fcbaf9441ed40d917baf1
+size 10318
diff --git a/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png
new file mode 100644
index 0000000000..57f1416310
--- /dev/null
+++ b/redwood-layout-view/src/test/snapshots/images/app.cash.redwood.layout.view_ViewFlexContainerTest_testFlexDistributesWeightUnequally[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9e5df9553cc1bb3e73a3df3c50cf33e6c98529cab0d1cecb4cad60d681a41da4
+size 10467
diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[LTR].png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[LTR].png
new file mode 100644
index 0000000000..9a2c59b3c2
--- /dev/null
+++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:acc62a51e5e2cb9fcbf2c66623255c90b2a9ec71fd8daa3cc91ffc9a0e8ad5ba
+size 10218
diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[RTL].png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[RTL].png
new file mode 100644
index 0000000000..236f4ef34b
--- /dev/null
+++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightEqually[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:21680269f0226afd516b2ee8f52a301260db3ab04d1c3cde39b3983827fde4ba
+size 10160
diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[LTR].png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[LTR].png
new file mode 100644
index 0000000000..9a2c59b3c2
--- /dev/null
+++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[LTR].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:acc62a51e5e2cb9fcbf2c66623255c90b2a9ec71fd8daa3cc91ffc9a0e8ad5ba
+size 10218
diff --git a/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[RTL].png b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[RTL].png
new file mode 100644
index 0000000000..236f4ef34b
--- /dev/null
+++ b/redwood-lazylayout-composeui/src/test/snapshots/images/app.cash.redwood.layout.composeui_ComposeUiLazyListTest_testFlexDistributesWeightUnequally[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:21680269f0226afd516b2ee8f52a301260db3ab04d1c3cde39b3983827fde4ba
+size 10160
diff --git a/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightEqually[LTR].png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightEqually[LTR].png
new file mode 100644
index 0000000000..ebb6a426ef
--- /dev/null
+++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightEqually[LTR].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_testFlexDistributesWeightEqually[RTL].png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightEqually[RTL].png
new file mode 100644
index 0000000000..ebb6a426ef
--- /dev/null
+++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightEqually[RTL].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_testFlexDistributesWeightUnequally[LTR].png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightUnequally[LTR].png
new file mode 100644
index 0000000000..ebb6a426ef
--- /dev/null
+++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightUnequally[LTR].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_testFlexDistributesWeightUnequally[RTL].png b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightUnequally[RTL].png
new file mode 100644
index 0000000000..ebb6a426ef
--- /dev/null
+++ b/redwood-lazylayout-view/src/test/snapshots/images/app.cash.redwood.lazylayout.view_ViewLazyListTest_testFlexDistributesWeightUnequally[RTL].png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cdca08973fd5cbf55a12717a65eaa147bbfaff662cc7dca62bcae0f9d63a9859
+size 3837
diff --git a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/Node.kt b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/Node.kt
index 85572bf044..a6d4a763c8 100644
--- a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/Node.kt
+++ b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/Node.kt
@@ -49,6 +49,13 @@ public class Node internal constructor(
public var flexShrink: Float
get() = Yoga.YGNodeStyleGetFlexShrink(native)
set(value) = Yoga.YGNodeStyleSetFlexShrink(native, value)
+ public var flexBasis: Float
+ get() = Yoga.YGNodeStyleGetFlexBasisPercent(native)
+ set(value) = if (value >= 0) {
+ Yoga.YGNodeStyleSetFlexBasisPercent(native, value)
+ } else {
+ Yoga.YGNodeStyleSetFlexBasisAuto(native)
+ }
public var marginStart: Float
get() = getMargin(YGEdge.YGEdgeStart)
set(value) = setMargin(YGEdge.YGEdgeStart, value)
diff --git a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/Yoga.kt b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/Yoga.kt
index fe1af179e6..7bc6f95c5b 100644
--- a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/Yoga.kt
+++ b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/Yoga.kt
@@ -796,6 +796,14 @@ internal object Yoga {
}
}
+ fun YGNodeStyleGetFlexBasisPercent(node: YGNode): Float {
+ return if (node.style.flexBasis.isPercent()) {
+ node.style.flexBasis.convertToYgValue().value
+ } else {
+ -1.0f // This is a stand-in for any non-percent value.
+ }
+ }
+
private fun > updateStyleIndexed(
node: YGNode,
edge: T,
diff --git a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/detail/CompactValue.kt b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/detail/CompactValue.kt
index 9a5255a159..61596509aa 100644
--- a/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/detail/CompactValue.kt
+++ b/redwood-yoga/src/commonMain/kotlin/app/cash/redwood/yoga/internal/detail/CompactValue.kt
@@ -34,11 +34,11 @@ internal class CompactValue {
return undefined || !isAuto() && !isPoint() && !isPercent() && payload_.value.isNaN()
}
- private fun isPercent(): Boolean {
+ fun isPercent(): Boolean {
return payload_.unit == YGUnit.YGUnitPercent
}
- private fun isPoint(): Boolean {
+ fun isPoint(): Boolean {
return payload_.unit == YGUnit.YGUnitPoint
}
diff --git a/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt b/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt
index 99407b94df..96209f8c4e 100644
--- a/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt
+++ b/samples/emoji-search/presenter/src/commonMain/kotlin/com/example/redwood/emojisearch/presenter/EmojiSearch.kt
@@ -34,7 +34,6 @@ import app.cash.redwood.layout.api.CrossAxisAlignment
import app.cash.redwood.layout.api.MainAxisAlignment
import app.cash.redwood.layout.compose.Column
import app.cash.redwood.layout.compose.Row
-import app.cash.redwood.layout.compose.flex
import app.cash.redwood.lazylayout.compose.ExperimentalRedwoodLazyLayoutApi
import app.cash.redwood.lazylayout.compose.LazyColumn
import app.cash.redwood.lazylayout.compose.items