Last active
November 19, 2023 07:47
-
-
Save mirokolodii/efa300454f32bb659bac16c2d7eb35c4 to your computer and use it in GitHub Desktop.
Custom View preview
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
@Preview | |
@Composable | |
fun CustomViewPreview( | |
@PreviewParameter(ViewStateProvider::class) params: PreviewParams, | |
) { | |
AndroidView( | |
modifier = Modifier | |
.fillMaxWidth() | |
.background(Color.White) | |
.padding(8.dp), | |
factory = { context -> | |
OrderView(context).apply { | |
init(params.status, params.items) | |
} | |
}, | |
) | |
} | |
class ViewStateProvider : PreviewParameterProvider<PreviewParams> { | |
override val values: Sequence<PreviewParams> = buildList { | |
Status.values().forEachIndexed { index, status -> | |
add(PreviewParams(status = status, items = previewItems[0])) | |
} | |
}.asSequence() | |
} | |
class PreviewParams( | |
val status: Status, | |
val items: Map<String, String>, | |
) | |
private val previewItems = listOf(mapOf("Dimension" to "34x12x8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment