Skip to content

//workflow/com.squareup.workflow1.ui

Package com.squareup.workflow1.ui

Types

Name Summary
AndroidViewRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

interface AndroidViewRendering<V : AndroidViewRendering<V>>
More info
Interface implemented by a rendering class to allow it to drive an Android UI via an appropriate ViewFactory implementation.


BackPressHandler [androidJvm]
Content
@WorkflowUiExperimentalApi()

typealias BackPressHandler = () -> Unit
More info


A function passed to View.backPressedHandler, to be called if the back button is pressed while that view is attached to a window.




BuilderViewFactory [androidJvm]
Content
@WorkflowUiExperimentalApi()

class BuilderViewFactory<RenderingT : Any>(type: KClass<RenderingT>, viewConstructor: (RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup?) -> View) : ViewFactory<RenderingT>
More info
A ViewFactory that creates Views that need to be generated from code.


Compatible [jvm]
Content
@WorkflowUiExperimentalApi()

interface Compatible
More info
Implemented by objects whose compatibility requires more nuance than just being of the same type.


DecorativeViewFactory [androidJvm]
Content
@WorkflowUiExperimentalApi()

class DecorativeViewFactory<OuterT : Any, InnerT : Any>(type: KClass<OuterT>, map: (OuterT, ViewEnvironment) -> Pair<InnerT, ViewEnvironment>, initializeView: View.() -> Unit, doShowRendering: (view: View, ViewShowRendering<InnerT>, OuterT, env: ViewEnvironment) -> Unit) : ViewFactory<OuterT>
More info
A ViewFactory for OuterT that delegates view construction responsibilities to the factory registered for InnerT.


LayoutRunner [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun fun interface LayoutRunner<RenderingT : Any>
More info
A delegate that implements a showRendering method to be called when a workflow rendering of type RenderingT is ready to be displayed in a view inflated from a layout resource by a ViewRegistry.


Named [jvm]
Content
@WorkflowUiExperimentalApi()

data class Named<W : Any>(wrapped: W, name: String) : Compatible
More info
Allows renderings that do not implement Compatible themselves to be distinguished by more than just their type.


NamedViewFactory [androidJvm]
Content
@WorkflowUiExperimentalApi()

object NamedViewFactory : ViewFactory<Named<*>>
More info
ViewFactory that allows views to display instances of Named.


ShowRenderingTag [androidJvm]
Content
@WorkflowUiExperimentalApi()

data class ShowRenderingTagRenderingT : Any>(showing: RenderingT, environment: ViewEnvironment, showRendering: ViewShowRendering<RenderingT>)
More info
` * View tag that holds the function to make the view show instances of RenderingT, and the current rendering.


ViewBindingInflater [androidJvm]
Content
@WorkflowUiExperimentalApi()

typealias ViewBindingInflater<BindingT> = (LayoutInflater, ViewGroup?, Boolean) -> BindingT


ViewEnvironment [androidJvm]
Content
@WorkflowUiExperimentalApi()

class ViewEnvironment(map: Map<ViewEnvironmentKey<*>, Any>)
More info
Immutable, append-only map of values that a parent view can pass down to its children via View.showRendering et al.


ViewEnvironmentKey [androidJvm]
Content
@WorkflowUiExperimentalApi()

abstract class ViewEnvironmentKey<T : Any>(type: KClass<T>)
More info
Defines a value that can be provided by a ViewEnvironment map, specifying its type and default value.


ViewFactory [androidJvm]
Content
@WorkflowUiExperimentalApi()

interface ViewFactoryRenderingT : Any>
More info
Factory for View instances that can show renderings of typeRenderingT.


ViewRegistry [androidJvm]
Content
@WorkflowUiExperimentalApi()

interface ViewRegistry
More info
The ViewEnvironment service that can be used to display the stream of renderings from a workflow tree as View instances.


ViewShowRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

typealias ViewShowRendering<RenderingT> = (@UnsafeVariance()RenderingT, ViewEnvironment) -> Unit
More info


Function attached to a view created by ViewFactory, to allow it to respond to View.showRendering.




WorkflowLayout [androidJvm]
Content
@WorkflowUiExperimentalApi()

class WorkflowLayout(context: Context, attributeSet: AttributeSet?) : FrameLayout
More info
A view that can be driven by a stream of renderings (and an optional ViewRegistry) passed to its start method.


WorkflowUiExperimentalApi [jvm]
Content
@Target(allowedTargets = [AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION, AnnotationTarget.TYPEALIAS])

annotation class WorkflowUiExperimentalApi
More info
Marks Workflow user interface APIs which are still in flux.


WorkflowViewStub [androidJvm]
Content
@WorkflowUiExperimentalApi()

class WorkflowViewStub@JvmOverloads()constructor(context: Context, attributeSet: AttributeSet?, defStyle: Int, defStyleRes: Int) : View
More info
A placeholder View that can replace itself with ones driven by workflow renderings, similar to android.view.ViewStub.


Functions

Name Summary
bindShowRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> View.bindShowRendering(initialRendering: RenderingT, initialViewEnvironment: ViewEnvironment, showRendering: ViewShowRendering<RenderingT>)
More info
Establishes showRendering as the implementation of View.showRendering for the receiver, possibly replacing the existing one.


buildView [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> ViewRegistry.buildView(initialRendering: RenderingT, initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? = null, initializeView: View.() -> Unit = { showFirstRendering() }): View
More info
It is usually more convenient to use WorkflowViewStub or DecorativeViewFactory than to call this method directly.


canShowRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun View.canShowRendering(rendering: Any): Boolean
More info
It is usually more convenient to use WorkflowViewStub than to call this method directly.


compatible [jvm]
Content
@WorkflowUiExperimentalApi()

fun compatible(me: Any, you: Any): Boolean
More info
Normally returns true if me and you are instances of the same class.


getFactoryForRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> ViewRegistry.getFactoryForRendering(rendering: RenderingT): ViewFactory<RenderingT>
More info
It is usually more convenient to use WorkflowViewStub or DecorativeViewFactory than to call this method directly.


getRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> View.getRendering(): RenderingT?
More info
Returns the most recent rendering shown by this view, or null if bindShowRendering has never been called.


getShowRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> View.getShowRendering(): ViewShowRendering<RenderingT>?
More info
Returns the function set by the most recent call to bindShowRendering, or null if that method has never been called.


onBackPressedDispatcherOwnerOrNull [androidJvm]
Content
@WorkflowUiExperimentalApi()

tailrec fun Context.onBackPressedDispatcherOwnerOrNull(): OnBackPressedDispatcherOwner?


plus [androidJvm]
Content
@WorkflowUiExperimentalApi()

operator fun ViewRegistry.plus(binding: ViewFactory<*>): ViewRegistry
@WorkflowUiExperimentalApi()

operator fun ViewRegistry.plus(other: ViewRegistry): ViewRegistry


renderWorkflowIn [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <OutputT, RenderingT> renderWorkflowIn(workflow: Workflow<Unit, OutputT, RenderingT>, scope: CoroutineScope, savedStateHandle: SavedStateHandle? = null, interceptors: List = emptyList(), onOutput: suspend (OutputT) -> Unit = {}): StateFlow<RenderingT>
More info
An Android ViewModel-friendly wrapper for com.squareup.workflow1.renderWorkflowIn, for use with a workflow that takes no input (that is, has PropsT set to Unit).


[androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <PropsT, OutputT, RenderingT> renderWorkflowIn(workflow: Workflow<PropsT, OutputT, RenderingT>, scope: CoroutineScope, prop: PropsT, savedStateHandle: SavedStateHandle? = null, interceptors: List = emptyList(), onOutput: suspend (OutputT) -> Unit = {}): StateFlow<RenderingT>
More info
An Android ViewModel-friendly wrapper for com.squareup.workflow1.renderWorkflowIn, for use with a workflow that requires one input value (prop) to run.


[androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <PropsT, OutputT, RenderingT> renderWorkflowIn(workflow: Workflow<PropsT, OutputT, RenderingT>, scope: CoroutineScope, props: StateFlow<PropsT>, savedStateHandle: SavedStateHandle? = null, interceptors: List = emptyList(), onOutput: suspend (OutputT) -> Unit = {}): StateFlow<RenderingT>
More info
An Android ViewModel-friendly wrapper for com.squareup.workflow1.renderWorkflowIn, for use with a workflow that requires input (props) to run.


setTextChangedListener [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun EditText.setTextChangedListener(listener: (CharSequence) -> Unit?)
More info
Helper for setting a simple function as a callback to be invoked whenever an EditText text value changes.


showFirstRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun View.showFirstRendering()
More info
Default implementation for the initializeView argument of ViewRegistry.buildView, and for DecorativeViewFactory.initializeView.


showRendering [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun <RenderingT : Any> View.showRendering(rendering: RenderingT, viewEnvironment: ViewEnvironment)
More info
It is usually more convenient to use WorkflowViewStub than to call this method directly.


toParcelable [androidJvm]
Content
inline fun <T : Parcelable> Snapshot.toParcelable(): T?
inline fun <T : Parcelable> ByteString.toParcelable(): T


toSnapshot [androidJvm]
Content
fun Parcelable.toSnapshot(): Snapshot
More info
Wraps receiver in a Snapshot suitable for use with com.squareup.workflow1.StatefulWorkflow.


updateText [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun EditText.updateText(text: CharSequence)
More info
Helper for setting the text value of an EditText without disrupting the IME connection, or firing change listeners registered via setTextChangedListener if the new text is actually different than the old text.


ViewRegistry [androidJvm]
Content
@WorkflowUiExperimentalApi()

fun ViewRegistry(): ViewRegistry
More info
Returns a ViewRegistry that contains no bindings.


[androidJvm]
Content
@WorkflowUiExperimentalApi()

fun ViewRegistry(vararg bindings: ViewFactory<*>): ViewRegistry


Properties

Name Summary
backPressedHandler [androidJvm] @WorkflowUiExperimentalApi()

var View.backPressedHandler: BackPressHandler?A function to be called if the device back button is pressed while this view is attached to a window.
environment [androidJvm] @WorkflowUiExperimentalApi()

val View.environment: ViewEnvironment?Returns the most recent ViewEnvironment that apply to this view, or null if bindShowRendering has never been called.