Preview

fun Screen.Preview(modifier: Modifier = Modifier, placeholderModifier: Modifier = Modifier, viewEnvironmentUpdater: (ViewEnvironment) -> ViewEnvironment? = null)

Uses ScreenComposableFactory.Preview or ScreenViewFactory.Preview to draw the receiving Screen.

Note that this function can preview any kind of Screen, whether it's bound to UI code implemented via Compose or classic View code.

Use inside @Preview Composable functions:

@Preview(heightDp = 150, showBackground = true)
@Composable
fun HelloPreview() {
  HelloScreen(
    "Hello!",
    onClick = {}
  ).Preview()
}

fun <RenderingT : Screen> ScreenComposableFactory<RenderingT>.Preview(rendering: RenderingT, modifier: Modifier = Modifier, placeholderModifier: Modifier = Modifier, viewEnvironmentUpdater: (ViewEnvironment) -> ViewEnvironment? = null)

Draws this ScreenComposableFactory using a special preview ScreenComposableFactoryFinder.

Use inside @Preview Composable functions:

@Preview(heightDp = 150, showBackground = true)
@Composable
fun DrawHelloRenderingPreview() {
  HelloBinding.Preview(HelloScreen("Hello!", onClick = {}))
}

Note: rendering must be the same type as this ScreenComposableFactory, even though the type system does not enforce this constraint. This is due to a Compose compiler bug tracked here.

Parameters

modifier

Modifier that will be applied to this ScreenComposableFactory.

placeholderModifier

Modifier that will be applied to any nested renderings this factory shows.

viewEnvironmentUpdater

Function that configures the ViewEnvironment passed to this factory.


fun <RenderingT : Screen> ScreenViewFactory<RenderingT>.Preview(rendering: RenderingT, modifier: Modifier = Modifier, placeholderModifier: Modifier = Modifier, viewEnvironmentUpdater: (ViewEnvironment) -> ViewEnvironment? = null)

Like ScreenComposableFactory.Preview, but for non-Compose ScreenViewFactory instances. Yes, you can preview classic View code this way.

Use inside @Preview Composable functions.

Note: rendering must be the same type as this ScreenViewFactory, even though the type system does not enforce this constraint. This is due to a Compose compiler bug tracked here.

Parameters

modifier

Modifier that will be applied to this ScreenViewFactory.

placeholderModifier

Modifier that will be applied to any nested renderings this factory shows.

viewEnvironmentUpdater

Function that configures the ViewEnvironment passed to this factory.