Doug McCluer
10/29/2025, 8:14 PM@Preview annotated function?Stylianos Gakis
10/29/2025, 10:20 PMDoug McCluer
10/29/2025, 11:03 PMVidmantas Kerbelis
10/30/2025, 7:43 AM@Composable @Preview
private fun ExamplePreview() {
@Composable
fun createPreviewBox(
color: Color,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier
.background(color)
.size(64.dp)
)
}
Column {
createPreviewBox(color = Color.Red)
createPreviewBox(color = Color.Green)
createPreviewBox(color = Color.Blue)
}
}
createPreviewBox() in this case will not be accessible anywhere but your preview functionDoug McCluer
10/30/2025, 2:30 PMcreatePreviewBox only accessible within that one function, right? Other Previews wouldn't have access to it? I was hoping to find something that could be available to any Preview function, but could not be used in production.
There are a couple use cases we were hoping to support:
1. Creating mock/fake data to populate the UI in Previews
2. Adding a label/wrapper/decoration to all the Previews in the module that displays some helpful info to developers.
Both of these use cases involve some code that's only for internal use - ideally we wouldn't ship it with our app and we don't want developers accidentally using in their production code. We also don't want to have to move the implementation of the Preview into some other location separate from the implementation of the Composable being Previewed as that would reduce the helpfulness of the Preview.Vidmantas Kerbelis
10/30/2025, 2:30 PMonly accessible within that one function, right? Other Previews wouldn't have access to it?Yes and yes.
Vidmantas Kerbelis
10/30/2025, 2:32 PM1. Creating mock/fake data to populate the UI in PreviewsUse debug / release sources for that. On Android of course, it's controlled for you when you're switching build types, here you will have to control that yourself and point to those source sets yourself.
Doug McCluer
10/30/2025, 2:44 PMTgo1014
10/30/2025, 2:45 PMDoug McCluer
10/30/2025, 2:49 PM