Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement test-only background color support for Compose UI spacer #2449

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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