Skip to content

Instantly share code, notes, and snippets.

@Ekt0s
Created April 28, 2022 23:14
Show Gist options
  • Save Ekt0s/078239bcaea76c8f79034df8e0fd8c5a to your computer and use it in GitHub Desktop.
Save Ekt0s/078239bcaea76c8f79034df8e0fd8c5a to your computer and use it in GitHub Desktop.
Quick sample to use PreviewParameterProvider
@Composable
fun MyCard(dumbo: Dummy) {
Box(
Modifier
.fillMaxWidth()
.height(64.dp)
.background(colorResource(id = R.color.colorPrimary))
) {
Text(text = dumbo.title)
}
}
@Preview(showBackground = true)
@Composable
fun PreviewCard(
@PreviewParameter(TestPreviewParameterProvider::class)
dumbo: Dummy) {
MyCard(dumbo)
}
val myDummy = Dummy("Title")
data class Dummy(val title: String)
class TestPreviewParameterProvider : PreviewParameterProvider<Dummy> {
override val values: Sequence<Dummy> = sequenceOf(
myDummy
)
}
/**
README
To use it, you just need to import the file inside an Android Project with Compose dependencies
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment