diff --git a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt index 8abd84967b..fdc3f3816d 100644 --- a/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt +++ b/redwood-layout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiFlexContainerTest.kt @@ -31,7 +31,6 @@ import app.cash.redwood.Modifier as RedwoodModifier import app.cash.redwood.layout.AbstractFlexContainerTest import app.cash.redwood.layout.TestFlexContainer import app.cash.redwood.layout.Text -import app.cash.redwood.layout.widget.Column import app.cash.redwood.layout.widget.FlexContainer import app.cash.redwood.widget.Widget import app.cash.redwood.yoga.FlexDirection @@ -53,16 +52,25 @@ class ComposeUiFlexContainerTest( supportsRtl = true, ) - override fun flexContainer(direction: FlexDirection) = ComposeTestFlexContainer(direction) + override fun flexContainer( + direction: FlexDirection, + backgroundColor: Int, + ): ComposeTestFlexContainer { + return ComposeTestFlexContainer(direction, backgroundColor) + } + + override fun row() = flexContainer(FlexDirection.Row) - override fun widget() = object : Text<@Composable () -> Unit> { + override fun column() = flexContainer(FlexDirection.Column) + + override fun widget(backgroundColor: Int) = object : Text<@Composable () -> Unit> { private var text by mutableStateOf("") override val value = @Composable { BasicText( text = this.text, style = TextStyle(fontSize = 18.sp, color = Color.Black), - modifier = Modifier.background(Color.Green), + modifier = Modifier.background(Color(backgroundColor)), ) } @@ -73,9 +81,6 @@ class ComposeUiFlexContainerTest( } } - override fun column(): Column<@Composable () -> Unit> = - ComposeUiFlexContainer(FlexDirection.Column) - override fun verifySnapshot(container: Widget<@Composable () -> Unit>, name: String?) { paparazzi.snapshot(name) { container.value() @@ -87,9 +92,9 @@ class ComposeUiFlexContainerTest( ) : TestFlexContainer<@Composable () -> Unit>, FlexContainer<@Composable () -> Unit> by delegate { private var childCount = 0 - constructor(direction: FlexDirection) : this( + constructor(direction: FlexDirection, backgroundColor: Int) : this( ComposeUiFlexContainer(direction).apply { - testOnlyModifier = Modifier.background(Color(0, 0, 255, 51)) + testOnlyModifier = Modifier.background(Color(backgroundColor)) }, ) 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 index b0ba0f43b7..21d3b5e65c 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d4fe7a57fab4f936b8dd2534e9cfe14a6f455a0874a7aa2134fb1990ab31bc08 -size 5195 +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 index 377ab4076d..c8383cb1a6 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca7b38828a0385925e7437f420940410b82dce939a1eb1968545fac92e34ef31 +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 index 050ff9e083..4c80c8a344 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0e6df6b0b6cd853e7c7702714ad851aa49267ebc4a168fad3488e7594c1e599b -size 5154 +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 index b05ee0bdc7..b21cab8c71 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6cfa432036f6cee35974095498ac97d80cad8572d03bffb8e26eefa6bffbc2ff -size 4506 +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 f4503275ea..8010334e13 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 @@ -29,6 +29,7 @@ import app.cash.redwood.layout.modifier.Size import app.cash.redwood.layout.modifier.VerticalAlignment import app.cash.redwood.layout.modifier.Width import app.cash.redwood.layout.widget.Column +import app.cash.redwood.layout.widget.Row import app.cash.redwood.ui.Dp import app.cash.redwood.ui.Margin import app.cash.redwood.ui.dp @@ -36,19 +37,37 @@ import app.cash.redwood.widget.ChangeListener import app.cash.redwood.widget.Widget import app.cash.redwood.yoga.FlexDirection import kotlin.test.Test -import kotlin.test.assertTrue abstract class AbstractFlexContainerTest { - abstract fun flexContainer(direction: FlexDirection): TestFlexContainer - abstract fun widget(): Text + abstract fun flexContainer( + direction: FlexDirection, + backgroundColor: Int = Color(51, 0, 0, 255), + ): TestFlexContainer + + abstract fun row(): Row + abstract fun column(): Column - abstract fun verifySnapshot(container: Widget, name: String? = null) - private fun widget(text: String, modifier: Modifier = Modifier): Text = widget().apply { - text(text) - this.modifier = modifier + abstract fun widget( + backgroundColor: Int = Green, + ): Text + + fun widget( + text: String, + modifier: Modifier = Modifier, + backgroundColor: Int = Green, + ): Text { + val widget = widget(backgroundColor) + widget.text(text) + widget.modifier = modifier + return widget } + abstract fun verifySnapshot( + container: Widget, + name: String? = null, + ) + @Test fun testEmptyLayout_Column() { emptyLayout(FlexDirection.Column) } @@ -232,8 +251,7 @@ abstract class AbstractFlexContainerTest { verifySnapshot(container) } - @Test - fun columnWithUpdatedCrossAxisAlignment() { + @Test fun columnWithUpdatedCrossAxisAlignment() { val container = flexContainer(FlexDirection.Column) container.width(Constraint.Fill) container.height(Constraint.Fill) @@ -419,8 +437,7 @@ abstract class AbstractFlexContainerTest { verifySnapshot(column) } - @Test - fun testDynamicElementUpdates() { + @Test fun testDynamicElementUpdates() { val container = flexContainer(FlexDirection.Column) container.width(Constraint.Fill) container.height(Constraint.Fill) @@ -441,8 +458,7 @@ abstract class AbstractFlexContainerTest { verifySnapshot(container, "BCDE") } - @Test - fun testDynamicContainerSize() { + @Test fun testDynamicContainerSize() { val parent = column().apply { width(Constraint.Fill) height(Constraint.Fill) @@ -497,8 +513,7 @@ abstract class AbstractFlexContainerTest { verifySnapshot(parent, "single") } - @Test - fun testFlexDistributesWeightEqually() { + @Test fun testFlexDistributesWeightEqually() { val container = flexContainer(FlexDirection.Row) container.width(Constraint.Fill) container.height(Constraint.Fill) @@ -509,8 +524,7 @@ abstract class AbstractFlexContainerTest { verifySnapshot(container) } - @Test - fun testFlexDistributesWeightUnequally() { + @Test fun testFlexDistributesWeightUnequally() { val container = flexContainer(FlexDirection.Row) container.width(Constraint.Fill) container.height(Constraint.Fill) @@ -520,11 +534,6 @@ abstract class AbstractFlexContainerTest { 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) - } } interface TestFlexContainer : Widget, ChangeListener { diff --git a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/utils.common.kt b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/utils.common.kt new file mode 100644 index 0000000000..60b0f5337d --- /dev/null +++ b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/utils.common.kt @@ -0,0 +1,39 @@ +/* + * 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. + */ +@file:Suppress("ktlint:standard:function-naming", "ktlint:standard:property-naming") + +package app.cash.redwood.layout + +import kotlin.test.assertTrue + +const val Transparent: Int = 0x00000000 +const val Red: Int = 0xffff0000.toInt() +const val Green: Int = 0xff00ff00.toInt() +const val Blue: Int = 0xff0000ff.toInt() + +fun Color( + alpha: Int, + red: Int, + green: Int, + blue: Int, +): Int { + return (alpha shl 24) or (red shl 16) or (green shl 8) or (blue) +} + +/** We don't have assume() on kotlin.test. Tests that fail here should be skipped instead. */ +fun assumeTrue(b: Boolean) { + assertTrue(b) +} diff --git a/redwood-layout-shared-test/src/iosMain/kotlin/app/cash/redwood/layout/utils.kt b/redwood-layout-shared-test/src/iosMain/kotlin/app/cash/redwood/layout/utils.kt new file mode 100644 index 0000000000..ccc4b57680 --- /dev/null +++ b/redwood-layout-shared-test/src/iosMain/kotlin/app/cash/redwood/layout/utils.kt @@ -0,0 +1,27 @@ +/* + * 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 + +import platform.UIKit.UIColor + +fun Int.toUIColor(): UIColor { + return UIColor( + red = ((this shr 16) and 0xff) / 255.0, + green = ((this shr 8) and 0xff) / 255.0, + blue = (this and 0xff) / 255.0, + alpha = ((this shr 24) and 0xff) / 255.0, + ) +} diff --git a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png index c22c45b904..f3397b1794 100644 --- a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png +++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.both.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ea9ad9c8b72b0b10b86a8a0743e292cf2883358dd62ac4082663377c9487379c -size 71152 +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 index cca3dd6d80..680502f40d 100644 --- a/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.single.png +++ b/redwood-layout-uiview/RedwoodLayoutUIViewTests/__Snapshots__/UIViewFlexContainerTestHost/testDynamicContainerSize.single.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:aa45f6cd047638974bd531ef4e9a01c7bd8bee05d055dce2fef50da46f9e339a +oid sha256:8d0b0322fa313b5a2e71c2a23ff1af419ca31aa0739230063ae77af0cbfdfd3e size 67288 diff --git a/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt b/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt index bf25ededfd..9be927862b 100644 --- a/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt +++ b/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt @@ -19,7 +19,7 @@ import app.cash.redwood.Modifier import app.cash.redwood.layout.AbstractFlexContainerTest import app.cash.redwood.layout.TestFlexContainer import app.cash.redwood.layout.Text -import app.cash.redwood.layout.widget.Column +import app.cash.redwood.layout.toUIColor import app.cash.redwood.layout.widget.FlexContainer import app.cash.redwood.widget.ChangeListener import app.cash.redwood.widget.Widget @@ -32,16 +32,25 @@ import platform.UIKit.UIView class UIViewFlexContainerTest( private val callback: UIViewSnapshotCallback, ) : AbstractFlexContainerTest() { - override fun flexContainer(direction: FlexDirection): TestFlexContainer { - return UIViewTestFlexContainer(UIViewFlexContainer(direction)) + override fun flexContainer( + direction: FlexDirection, + backgroundColor: Int, + ): UIViewTestFlexContainer { + val container = UIViewTestFlexContainer(UIViewFlexContainer(direction)) + container.value.backgroundColor = backgroundColor.toUIColor() + return container } - override fun widget(): Text { + override fun row() = flexContainer(FlexDirection.Row) + + override fun column() = flexContainer(FlexDirection.Column) + + override fun widget(backgroundColor: Int): Text { return object : Text { override val value = UILabel().apply { - numberOfLines = 0 - backgroundColor = UIColor.greenColor - textColor = UIColor.blackColor + this.numberOfLines = 0 + this.backgroundColor = backgroundColor.toUIColor() + this.textColor = UIColor.blackColor } override var modifier: Modifier = Modifier @@ -52,8 +61,6 @@ class UIViewFlexContainerTest( } } - override fun column(): Column = UIViewFlexContainer(FlexDirection.Column) - class UIViewTestFlexContainer internal constructor( private val delegate: UIViewFlexContainer, ) : TestFlexContainer, FlexContainer by delegate, ChangeListener by delegate { diff --git a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt index d25723ead7..5230fcafc0 100644 --- a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt +++ b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt @@ -17,7 +17,6 @@ package app.cash.redwood.layout.view import android.content.Context import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.view.View import android.widget.TextView import app.cash.paparazzi.DeviceConfig @@ -26,7 +25,6 @@ import app.cash.redwood.Modifier import app.cash.redwood.layout.AbstractFlexContainerTest import app.cash.redwood.layout.TestFlexContainer import app.cash.redwood.layout.Text -import app.cash.redwood.layout.widget.Column import app.cash.redwood.layout.widget.FlexContainer import app.cash.redwood.widget.ChangeListener import app.cash.redwood.widget.Widget @@ -49,13 +47,20 @@ class ViewFlexContainerTest( supportsRtl = true, ) - override fun flexContainer(direction: FlexDirection): TestFlexContainer { - return ViewTestFlexContainer(paparazzi.context, direction) + override fun flexContainer( + direction: FlexDirection, + backgroundColor: Int, + ): ViewTestFlexContainer { + return ViewTestFlexContainer(paparazzi.context, direction, backgroundColor) } - override fun widget() = object : Text { + override fun row() = flexContainer(FlexDirection.Row) + + override fun column() = flexContainer(FlexDirection.Column) + + override fun widget(backgroundColor: Int) = object : Text { override val value = TextView(paparazzi.context).apply { - background = ColorDrawable(Color.GREEN) + setBackgroundColor(backgroundColor) textSize = 18f textDirection = View.TEXT_DIRECTION_LOCALE setTextColor(Color.BLACK) @@ -68,8 +73,6 @@ class ViewFlexContainerTest( } } - override fun column(): Column = ViewFlexContainer(paparazzi.context, FlexDirection.Column) - override fun verifySnapshot(container: Widget, name: String?) { paparazzi.snapshot(container.value, name) } @@ -79,9 +82,9 @@ class ViewFlexContainerTest( ) : TestFlexContainer, FlexContainer by delegate, ChangeListener by delegate { private var childCount = 0 - constructor(context: Context, direction: FlexDirection) : this( + constructor(context: Context, direction: FlexDirection, backgroundColor: Int) : this( ViewFlexContainer(context, direction).apply { - value.setBackgroundColor(Color.argb(51, 0, 0, 255)) + value.setBackgroundColor(backgroundColor) }, ) 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 index 2ed0b5712f..7f3ca87b21 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a618e96eb5d9c25618c04827c1e2073c94d3855198a75bbfe42157e5e539310a -size 5037 +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 index 5623599453..727937df6f 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c4c5b2a52e400e4c2d07a299c8fad47de6ada7739384b37a5bac741f2f686b71 -size 4429 +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 index b14e7ac24c..801ba837e2 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c0cb7e0c76eaa5c4677c7e6bfbf1be634ede4084799bd15ee2a185e5adcca8aa -size 5019 +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 index 08cac39721..7c6e68701b 100644 --- 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 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a9c2a5298aa28c84dd59f742220a10615c82facd60b421c27a817293adc6905 -size 4426 +oid sha256:0752287d527e479efad0f29e745abeeb67eb9b6b84e8893a5bfaa02ac749c6c7 +size 4425 diff --git a/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt b/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt index 9f869fe6ac..1fa785e31a 100644 --- a/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt +++ b/redwood-lazylayout-composeui/src/androidUnitTest/kotlin/app/cash/redwood/layout/composeui/ComposeUiLazyListTest.kt @@ -33,6 +33,7 @@ import app.cash.redwood.layout.TestFlexContainer import app.cash.redwood.layout.Text import app.cash.redwood.layout.api.MainAxisAlignment import app.cash.redwood.layout.widget.Column +import app.cash.redwood.layout.widget.Row import app.cash.redwood.lazylayout.composeui.ComposeUiLazyList import app.cash.redwood.lazylayout.widget.LazyList import app.cash.redwood.widget.Widget @@ -55,16 +56,29 @@ class ComposeUiLazyListTest( supportsRtl = true, ) - override fun flexContainer(direction: FlexDirection) = ComposeTestFlexContainer(direction) + override fun flexContainer( + direction: FlexDirection, + backgroundColor: Int, + ): ComposeTestFlexContainer { + return ComposeTestFlexContainer(direction, backgroundColor) + } + + override fun row(): Row<@Composable () -> Unit> { + return ComposeUiRedwoodLayoutWidgetFactory().Row() + } - override fun widget() = object : Text<@Composable () -> Unit> { + override fun column(): Column<@Composable () -> Unit> { + return ComposeUiRedwoodLayoutWidgetFactory().Column() + } + + override fun widget(backgroundColor: Int) = object : Text<@Composable () -> Unit> { private var text by mutableStateOf("") override val value = @Composable { BasicText( text = this.text, style = TextStyle(fontSize = 18.sp, color = Color.Black), - modifier = Modifier.background(Color.Green), + modifier = Modifier.background(Color(backgroundColor)), ) } @@ -75,9 +89,6 @@ class ComposeUiLazyListTest( } } - override fun column(): Column<@Composable () -> Unit> = - ComposeUiRedwoodLayoutWidgetFactory().Column() - override fun verifySnapshot(container: Widget<@Composable () -> Unit>, name: String?) { paparazzi.snapshot(name) { container.value() @@ -89,10 +100,10 @@ class ComposeUiLazyListTest( ) : TestFlexContainer<@Composable () -> Unit>, LazyList<@Composable () -> Unit> by delegate { private var childCount = 0 - constructor(direction: FlexDirection) : this( + constructor(direction: FlexDirection, backgroundColor: Int) : this( ComposeUiLazyList().apply { isVertical(direction == FlexDirection.Column) - testOnlyModifier = Modifier.background(Color(0, 0, 255, 51)) + testOnlyModifier = Modifier.background(Color(backgroundColor)) }, ) diff --git a/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt b/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt index 0f6c706993..05a316cae7 100644 --- a/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt +++ b/redwood-lazylayout-view/src/test/kotlin/app/cash/redwood/lazylayout/view/ViewLazyListTest.kt @@ -17,7 +17,6 @@ package app.cash.redwood.lazylayout.view import android.content.Context import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.view.View import android.widget.TextView import app.cash.paparazzi.DeviceConfig @@ -29,6 +28,7 @@ import app.cash.redwood.layout.Text import app.cash.redwood.layout.api.MainAxisAlignment import app.cash.redwood.layout.view.ViewRedwoodLayoutWidgetFactory import app.cash.redwood.layout.widget.Column +import app.cash.redwood.layout.widget.Row import app.cash.redwood.lazylayout.widget.LazyList import app.cash.redwood.widget.ChangeListener import app.cash.redwood.widget.Widget @@ -51,11 +51,24 @@ class ViewLazyListTest( supportsRtl = true, ) - override fun flexContainer(direction: FlexDirection) = ViewTestFlexContainer(paparazzi.context, direction) + override fun flexContainer( + direction: FlexDirection, + backgroundColor: Int, + ): TestFlexContainer { + return ViewTestFlexContainer(paparazzi.context, direction, backgroundColor) + } + + override fun row(): Row { + return ViewRedwoodLayoutWidgetFactory(paparazzi.context).Row() + } - override fun widget() = object : Text { + override fun column(): Column { + return ViewRedwoodLayoutWidgetFactory(paparazzi.context).Column() + } + + override fun widget(backgroundColor: Int) = object : Text { override val value = TextView(paparazzi.context).apply { - background = ColorDrawable(Color.GREEN) + setBackgroundColor(backgroundColor) textSize = 18f setTextColor(Color.BLACK) } @@ -67,8 +80,6 @@ class ViewLazyListTest( } } - override fun column(): Column = ViewRedwoodLayoutWidgetFactory(paparazzi.context).Column() - override fun verifySnapshot(container: Widget, name: String?) { paparazzi.snapshot(container.value, name) } @@ -78,10 +89,10 @@ class ViewLazyListTest( ) : TestFlexContainer, LazyList by delegate, ChangeListener by delegate { private var childCount = 0 - constructor(context: Context, direction: FlexDirection) : this( + constructor(context: Context, direction: FlexDirection, backgroundColor: Int) : this( ViewLazyList(context).apply { isVertical(direction == FlexDirection.Column) - value.setBackgroundColor(Color.argb(51, 0, 0, 255)) + value.setBackgroundColor(backgroundColor) }, )