A2uiPreviewParameterProvider

open class A2uiPreviewParameterProvider : PreviewParameterProvider<A2uiSurfaceModelFactory>


Converts raw A2UI JSON protocol messages into A2uiSurfaceModelFactory instances for Compose @Preview functions.

Each list of messages must include at least a createSurface message, which initializes the surface, and an updateComponents message, which defines the components to render. If the components bind to values in the surface's data model, the list may also include updateDataModel messages to populate it.

Call A2uiSurfaceModelFactory.create inside the @Preview composable and pass the resulting A2uiSurfaceModel to an A2UI surface composable, such as A2uiSurface when using the Compose Material 3 A2UI APIs:

val OrderConfirmationMessages = listOf(
"""{"version": "v0.9", "createSurface": {"surfaceId": "preview_surface", "catalogId": "..."}}""",
"""{"version": "v0.9", "updateComponents": {"surfaceId": "preview_surface", "components": [...]}}""",
)


class MyOrderPreviewProvider : A2uiPreviewParameterProvider(
catalog = { rememberMyCatalog() },
namedJsonMessages = mapOf("Order Confirmation" to OrderConfirmationMessages),
)


@Preview
@Composable
fun
OrderPreview(
@PreviewParameter(MyOrderPreviewProvider::class) surfaceFactory: A2uiSurfaceModelFactory
) {
A2uiSurface(surfaceModel = surfaceFactory.create())
}

Summary

Public constructors

A2uiPreviewParameterProvider(
    catalog: A2uiCatalog,
    jsonMessages: List<String>
)

Creates a provider for a single surface using a static catalog instance.

A2uiPreviewParameterProvider(
    catalog: A2uiCatalog,
    namedJsonMessages: Map<String, List<String>>
)

Creates a provider for multiple named surfaces using a static catalog instance.

A2uiPreviewParameterProvider(
    catalogProvider: @Composable () -> A2uiCatalog,
    jsonMessages: List<String>
)

Creates a provider for a single surface using a @Composable catalog provider.

A2uiPreviewParameterProvider(
    catalogProvider: @Composable () -> A2uiCatalog,
    namedJsonMessages: Map<String, List<String>>
)

Creates a provider for multiple named surfaces using a @Composable catalog provider.

Public functions

open String?

Public properties

open Sequence<A2uiSurfaceModelFactory>

Public constructors

A2uiPreviewParameterProvider

Added in 1.0.0-alpha03
A2uiPreviewParameterProvider(
    catalog: A2uiCatalog,
    jsonMessages: List<String>
)

Creates a provider for a single surface using a static catalog instance.

Parameters
catalog: A2uiCatalog

A2uiCatalog defining the components available to the surface

jsonMessages: List<String>

list of raw A2UI JSON protocol strings for the surface, which must include a createSurface message

A2uiPreviewParameterProvider

A2uiPreviewParameterProvider(
    catalog: A2uiCatalog,
    namedJsonMessages: Map<String, List<String>>
)

Creates a provider for multiple named surfaces using a static catalog instance.

Parameters
catalog: A2uiCatalog

A2uiCatalog defining the components available to the surfaces

namedJsonMessages: Map<String, List<String>>

map of display names to lists of raw A2UI JSON protocol strings, where each list must include a createSurface message

A2uiPreviewParameterProvider

A2uiPreviewParameterProvider(
    catalogProvider: @Composable () -> A2uiCatalog,
    jsonMessages: List<String>
)

Creates a provider for a single surface using a @Composable catalog provider.

Parameters
catalogProvider: @Composable () -> A2uiCatalog

@Composable provider returning the A2uiCatalog for the surface

jsonMessages: List<String>

list of raw A2UI JSON protocol strings for the surface, which must include a createSurface message

A2uiPreviewParameterProvider

A2uiPreviewParameterProvider(
    catalogProvider: @Composable () -> A2uiCatalog,
    namedJsonMessages: Map<String, List<String>>
)

Creates a provider for multiple named surfaces using a @Composable catalog provider.

Parameters
catalogProvider: @Composable () -> A2uiCatalog

@Composable provider returning the A2uiCatalog for the surfaces

namedJsonMessages: Map<String, List<String>>

map of display names to lists of raw A2UI JSON protocol strings, where each list must include a createSurface message

Public functions

getDisplayName

open fun getDisplayName(index: Int): String?

Public properties

values

Added in 1.0.0-alpha03
open val values: Sequence<A2uiSurfaceModelFactory>