Skip to content

//workflow/com.squareup.workflow1.ui/BuilderViewFactory

BuilderViewFactory

[androidJvm] @WorkflowUiExperimentalApi()

class BuilderViewFactory<RenderingT : Any>(type: KClass<RenderingT>, viewConstructor: (RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup?) -> View) : ViewFactory<RenderingT>

This will be deprecated in favor of ScreenViewFactory.fromCode very soon.

A ViewFactory that creates Views that need to be generated from code. (Use LayoutRunner to work with XML layout resources.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data class MyView(): AndroidViewRendering<MyView> {
  val viewFactory = BuilderViewFactory(
      type = MyScreen::class,
      viewConstructor = { initialRendering, _, context, _ ->
        MyFrame(context).apply {
          layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
          bindShowRendering(initialRendering, ::update)
        }
  )
}

private class MyFrame(context: Context) : FrameLayout(context, attributeSet) {
  private fun update(rendering:  MyView) { ... }
}

Constructors

BuilderViewFactory [androidJvm] fun <RenderingT : Any> BuilderViewFactory(type: KClass<RenderingT>, viewConstructor: (RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup?) -> View)

Functions

Name Summary
buildView [androidJvm]
Content
open override fun buildView(initialRendering: RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup?): View
More info
Returns a View ready to display initialRendering (and any succeeding values) via View.showRendering.


Properties

Name Summary
type [androidJvm] open override val type: KClass<RenderingT>