Skip to content

//workflow/com.squareup.workflow1.ui.compose/ComposeViewFactory

ComposeViewFactory

[androidJvm] @WorkflowUiExperimentalApi()

abstract class ComposeViewFactory<RenderingT : Any> : ViewFactory<RenderingT>

A ViewFactory that uses a Composable function to display the rendering. It is the Compose-based analogue of LayoutRunner.

Simple usage:

class FooViewFactory : ComposeViewFactory() {
override val type = Foo::class

@Composable override fun Content(
rendering: Foo,
viewEnvironment: ViewEnvironment
) {
Text(rendering.message)
}
}

val viewRegistry = ViewRegistry(FooViewFactory, …)

Nesting child renderings

Workflows can render other workflows, and renderings from one workflow can contain renderings from other workflows. These renderings may all be bound to their own ViewFactorys. Regular ViewFactorys and LayoutRunners use WorkflowViewStub to recursively show nested renderings using the ViewRegistry.

View factories defined using this function may also show nested renderings. Doing so is as simple as calling WorkflowRendering and passing in the nested rendering. See the kdoc on that function for an example.

Nested renderings will have access to any composition locals defined in outer composable, even if there are legacy views in between them, as long as the ViewEnvironment is propagated continuously between the two factories.

Initializing Compose context

Often all the composeViewFactory factories in an app need to share some context – for example, certain composition locals need to be provided, such as MaterialTheme. To configure this shared context, call withCompositionRoot on your top-level ViewEnvironment. The first time a composeViewFactory is used to show a rendering, its Content function will be wrapped with the CompositionRoot. See the documentation on CompositionRoot for more information.

Constructors

ComposeViewFactory [androidJvm] fun ComposeViewFactory()

Functions

Name Summary
buildView [androidJvm]
Content
override fun buildView(initialRendering: RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup?): View


Content [androidJvm]
Content
@Composable()

abstract fun Content(rendering: RenderingT, viewEnvironment: ViewEnvironment)
More info
The composable content of this ViewFactory.


Properties

Name Summary
type [androidJvm] abstract val type: KClassRenderingT>