Created
April 28, 2022 23:14
-
-
Save Ekt0s/078239bcaea76c8f79034df8e0fd8c5a to your computer and use it in GitHub Desktop.
Quick sample to use PreviewParameterProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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