Skip to content

Commit

Permalink
Implement test-only background color support for Compose UI spacer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton authored Nov 13, 2024
1 parent 32c53e6 commit 3d049b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3d049b9

Please sign in to comment.