From 44700b81b3fb99781557c1e1f2f32857fa29eae3 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Wed, 13 Nov 2024 14:55:55 -0500 Subject: [PATCH] Implement test-only background color support for Compose UI spacer --- .../redwood/layout/composeui/ComposeUiFlexContainerTest.kt | 5 +++-- .../app/cash/redwood/layout/composeui/ComposeUiSpacer.kt | 5 ++++- .../cash/redwood/layout/composeui/ComposeUiLazyListTest.kt | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) 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 7f643ba239..d742d6f0b6 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 @@ -72,8 +72,9 @@ class ComposeUiFlexContainerTest( } override fun spacer(backgroundColor: Int): Spacer<@Composable () -> Unit> { - // TODO: honor backgroundColor. - return ComposeUiSpacer() + return ComposeUiSpacer().apply { + testOnlyModifier = Modifier.background(Color(backgroundColor)) + } } override fun snapshotter(widget: @Composable () -> Unit) = ComposeSnapshotter(paparazzi, widget) diff --git a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacer.kt b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacer.kt index 0f7d39182c..fa5e2dd330 100644 --- a/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacer.kt +++ b/redwood-layout-composeui/src/commonMain/kotlin/app/cash/redwood/layout/composeui/ComposeUiSpacer.kt @@ -30,9 +30,12 @@ import app.cash.redwood.ui.dp internal class ComposeUiSpacer : Spacer<@Composable () -> Unit> { private var width by mutableStateOf(0.dp) private var height by mutableStateOf(0.dp) + var testOnlyModifier: Modifier? = null override val value = @Composable { - Spacer(Modifier.defaultMinSize(width.toDp(), height.toDp())) + var modifier = Modifier.defaultMinSize(width.toDp(), height.toDp()) + testOnlyModifier?.let { modifier = modifier.then(it) } + Spacer(modifier) } override var modifier: RedwoodModifier = RedwoodModifier 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 586c6cb422..d26df9ca02 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 @@ -70,8 +70,11 @@ class ComposeUiLazyListTest( } override fun spacer(backgroundColor: Int): Spacer<@Composable () -> Unit> { - // TODO: honor backgroundColor. - return ComposeUiRedwoodLayoutWidgetFactory().Spacer() + return ComposeUiRedwoodLayoutWidgetFactory().Spacer().apply { + @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") + (this as ComposeUiSpacer).testOnlyModifier = + Modifier.background(Color(backgroundColor)) + } } override fun snapshotter(widget: @Composable () -> Unit) = ComposeSnapshotter(paparazzi, widget)