Skip to content

//workflow/com.squareup.workflow1.ui/AndroidScreen

AndroidScreen

[androidJvm] @WorkflowUiExperimentalApi()

interface AndroidScreen<S : AndroidScreen<S>> : Screen

Interface implemented by a rendering class to allow it to drive an Android UI via an appropriate ScreenViewFactory implementation.

You will rarely, if ever, write a ScreenViewFactory yourself. Use one of its companion methods like ScreenViewFactory.fromViewBinding instead.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data class HelloScreen(
  val message: String,
  val onClick: () -> Unit
) : AndroidScreen<HelloScreen> {
  override val viewFactory : ScreenViewFactory<HelloScreen> =
    forViewBinding(HelloGoodbyeLayoutBinding::inflate) { screen, _ ->
      helloMessage.text = screen.message
      helloMessage.setOnClickListener { screen.onClick() }
    }
}

This is the simplest way to bridge the gap between your workflows and the UI, but using it requires your workflows code to reside in Android modules, instead of pure Kotlin. If this is a problem, or you need more flexibility for any other reason, you can use ViewRegistry to bind your renderings to ScreenViewFactory implementations at runtime.

Also note that a ViewRegistry entry will override the viewFactory returned by an AndroidScreen. This means that an AndroidScreen implementation can provide a default UI that can be completely customized at runtime via ViewRegistry configuration.

See also ScreenViewFactoryFinder to customize built in rendering types like BackStackScreen.

See also

androidJvm

com.squareup.workflow1.ui.container.AndroidOverlay

Properties

Name Summary
viewFactory [androidJvm] abstract val viewFactory: ScreenViewFactory<S>Used to build instances of android.view.View as needed to display renderings of this type.

Inheritors

Name
ComposeScreen
BackButtonScreen