From 3bb2f1f4e32b58e3c74d7d5876f59c4699f260bc Mon Sep 17 00:00:00 2001 From: Zach Klippenstein Date: Tue, 19 May 2020 16:56:47 -0700 Subject: [PATCH] Rename bindCompose to composedViewFactory. Fixes #19. --- README.md | 8 ++++---- .../ui/compose/tooling/PreviewViewFactoryTest.kt | 10 +++++----- .../ui/compose/tooling/PlaceholderViewFactory.kt | 4 ++-- .../workflow/ui/compose/ComposeViewFactoryTest.kt | 2 +- .../ui/compose/internal/ViewFactoriesTest.kt | 4 ++-- .../squareup/workflow/ui/compose/ComposeRendering.kt | 2 +- .../workflow/ui/compose/ComposeViewFactory.kt | 12 ++++++------ .../workflow/ui/compose/ComposeViewFactoryRoot.kt | 12 ++++++------ .../squareup/workflow/ui/compose/ComposeWorkflow.kt | 2 +- .../squareup/workflow/ui/compose/ViewEnvironments.kt | 2 +- .../ui/compose/internal/ParentComposition.kt | 4 ++-- .../workflow/ui/compose/internal/ViewFactories.kt | 3 ++- .../workflow/ui/compose/internal/ViewRegistries.kt | 2 +- .../sample/hellocomposebinding/HelloBinding.kt | 4 ++-- .../com/squareup/sample/hellocompose/HelloBinding.kt | 4 ++-- .../sample/nestedrenderings/RecursiveViewFactory.kt | 4 ++-- 16 files changed, 40 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 50c5ffc5..521d5b13 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,11 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } ``` -To create a `ViewFactory`, call `bindCompose`. The lambda passed to `bindCompose` is a `@Composable` -function. +To create a `ViewFactory`, call `composedViewFactory`. The lambda passed to `composedViewFactory` is +a `@Composable` function. ```kotlin -val HelloBinding = bindCompose { rendering, _ -> +val HelloBinding = composedViewFactory { rendering, _ -> MaterialTheme { Clickable(onClick = { rendering.onClick() }) { Text(rendering.message) @@ -75,7 +75,7 @@ val HelloBinding = bindCompose { rendering, _ -> } ``` -The `bindCompose` function returns a regular [`ViewFactory`][2] which can be added to a +The `composedViewFactory` function returns a regular [`ViewFactory`][2] which can be added to a [`ViewRegistry`][3] like any other: ```kotlin diff --git a/compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt b/compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt index cab900a5..b09ff3bd 100644 --- a/compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt +++ b/compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt @@ -31,7 +31,7 @@ import androidx.ui.test.findByText import androidx.ui.tooling.preview.Preview import androidx.ui.unit.dp import com.squareup.workflow.ui.ViewEnvironmentKey -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory import com.squareup.workflow.ui.compose.showRendering import org.junit.Rule import org.junit.Test @@ -99,7 +99,7 @@ class PreviewViewFactoryTest { findByText("foo").assertIsDisplayed() } - private val ParentWithOneChild = bindCompose> { rendering, environment -> + private val ParentWithOneChild = composedViewFactory> { rendering, environment -> Column { Text(rendering.first) Semantics(container = true, mergeAllDescendants = true) { @@ -113,7 +113,7 @@ class PreviewViewFactoryTest { } private val ParentWithTwoChildren = - bindCompose> { rendering, environment -> + composedViewFactory> { rendering, environment -> Column { Semantics(container = true) { environment.showRendering(rendering = rendering.first) @@ -134,7 +134,7 @@ class PreviewViewFactoryTest { val child: RecursiveRendering? = null ) - private val ParentRecursive = bindCompose { rendering, environment -> + private val ParentRecursive = composedViewFactory { rendering, environment -> Column { Text(rendering.text) rendering.child?.let { child -> @@ -175,7 +175,7 @@ class PreviewViewFactoryTest { override val default: String get() = error("Not specified") } - private val ParentConsumesCustomKey = bindCompose { _, environment -> + private val ParentConsumesCustomKey = composedViewFactory { _, environment -> Text(environment[TestEnvironmentKey]) } diff --git a/compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt b/compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt index fae90a78..9987b25b 100644 --- a/compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt +++ b/compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt @@ -42,14 +42,14 @@ import androidx.ui.unit.dp import androidx.ui.unit.px import androidx.ui.unit.toRect import com.squareup.workflow.ui.ViewFactory -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory /** * A [ViewFactory] that will be used any time a [PreviewViewRegistry] is asked to show a rendering. * It displays a placeholder graphic and the rendering's `toString()` result. */ internal fun placeholderViewFactory(modifier: Modifier): ViewFactory = - bindCompose { rendering, _ -> + composedViewFactory { rendering, _ -> Text( modifier = modifier .clipToBounds() diff --git a/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/ComposeViewFactoryTest.kt b/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/ComposeViewFactoryTest.kt index 510c4fbf..af6a87c8 100644 --- a/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/ComposeViewFactoryTest.kt +++ b/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/ComposeViewFactoryTest.kt @@ -71,7 +71,7 @@ class ComposeViewFactoryTest { private data class TestRendering(val text: String) private companion object { - val TestFactory = bindCompose { rendering, _ -> + val TestFactory = composedViewFactory { rendering, _ -> Text(rendering.text) } } diff --git a/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/internal/ViewFactoriesTest.kt b/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/internal/ViewFactoriesTest.kt index 1d4abc77..110a76b5 100644 --- a/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/internal/ViewFactoriesTest.kt +++ b/core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/internal/ViewFactoriesTest.kt @@ -23,7 +23,7 @@ import androidx.ui.test.createComposeRule import androidx.ui.test.findByText import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.ViewRegistry -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory import com.squareup.workflow.ui.compose.showRendering import com.squareup.workflow.ui.compose.withComposeViewFactoryRoot import org.junit.Rule @@ -54,7 +54,7 @@ class ViewFactoriesTest { private data class TestRendering(val text: String) private companion object { - val TestFactory = bindCompose { rendering, _ -> + val TestFactory = composedViewFactory { rendering, _ -> Text(rendering.text) } } diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeRendering.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeRendering.kt index 466fcafd..7e1b97ce 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeRendering.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeRendering.kt @@ -38,7 +38,7 @@ class ComposeRendering internal constructor( /** * A [ViewFactory] that renders a [ComposeRendering]. */ - val Factory: ViewFactory = bindCompose { rendering, environment -> + val Factory: ViewFactory = composedViewFactory { rendering, environment -> rendering.render(environment) } diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt index 6bbb6c7b..a67cf1c9 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt @@ -43,7 +43,7 @@ import kotlin.reflect.KClass * * ``` * // Function references to @Composable functions aren't supported yet. - * val FooBinding = bindCompose { showFoo(it) } + * val FooBinding = composedViewFactory { showFoo(it) } * * @Composable * private fun showFoo(foo: FooRendering) { @@ -73,14 +73,14 @@ import kotlin.reflect.KClass * * ## Initializing Compose context * - * Often all the [bindCompose] factories in an app need to share some context – for example, certain + * Often all the [composedViewFactory]s in an app need to share some context – for example, certain * ambients need to be provided, such as `MaterialTheme`. To configure this shared context, include * a [ComposeViewFactoryRoot] in your top-level [ViewEnvironment] (e.g. by using - * [withComposeViewFactoryRoot]). The first time a [bindCompose] is used to show a rendering, its - * [showRendering] function will be wrapped with the [ComposeViewFactoryRoot]. See the documentation - * on [ComposeViewFactoryRoot] for more information. + * [withComposeViewFactoryRoot]). The first time a [composedViewFactory] is used to show a + * rendering, its [showRendering] function will be wrapped with the [ComposeViewFactoryRoot]. + * See the documentation on [ComposeViewFactoryRoot] for more information. */ -inline fun bindCompose( +inline fun composedViewFactory( noinline showRendering: @Composable() ( rendering: RenderingT, environment: ViewEnvironment diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactoryRoot.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactoryRoot.kt index 23163615..34e4667e 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactoryRoot.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactoryRoot.kt @@ -33,12 +33,12 @@ private val HasViewFactoryRootBeenApplied = staticAmbientOf { false } /** * A `@Composable` function that is stored in a [ViewEnvironment] and will be used to wrap the first - * [bindCompose] composition. This can be used to setup any ambients that all [bindCompose] - * factories need access to, such as ambients that specify the UI theme. + * [composedViewFactory] composition. This can be used to setup any ambients that all + * [composedViewFactory]s need access to, such as ambients that specify the UI theme. * - * This function will called once, to wrap the _highest-level_ [bindCompose] in the tree. However, - * ambients are propagated down to child [bindCompose] compositions, so any ambients provided here - * will be available in _all_ [bindCompose] compositions. + * This function will called once, to wrap the _highest-level_ [composedViewFactory] in the tree. + * However, ambients are propagated down to child [composedViewFactory] compositions, so any + * ambients provided here will be available in _all_ [composedViewFactory] compositions. */ interface ComposeViewFactoryRoot { @@ -51,7 +51,7 @@ interface ComposeViewFactoryRoot { /** * Adds a [ComposeViewFactoryRoot] to this [ViewEnvironment] that uses [wrapper] to wrap the first - * [bindCompose] composition. See [ComposeViewFactoryRoot] for more information. + * [composedViewFactory] composition. See [ComposeViewFactoryRoot] for more information. */ fun ViewEnvironment.withComposeViewFactoryRoot( wrapper: @Composable() (content: @Composable() () -> Unit) -> Unit diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeWorkflow.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeWorkflow.kt index 1a30bcb6..0af19c3f 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeWorkflow.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeWorkflow.kt @@ -27,7 +27,7 @@ import com.squareup.workflow.ui.compose.internal.ComposeWorkflowImpl /** * A stateless [Workflow][com.squareup.workflow.Workflow] that [renders][render] itself as * [Composable] function. Effectively defines an inline - * [bindCompose][com.squareup.workflow.ui.compose.bindCompose]. + * [composedViewFactory][com.squareup.workflow.ui.compose.composedViewFactory]. * * This workflow does not have access to a [RenderContext][com.squareup.workflow.RenderContext] * since render contexts are only valid during render passes, and this workflow's [render] method diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ViewEnvironments.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ViewEnvironments.kt index cdb618f5..aabd9c4f 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/ViewEnvironments.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/ViewEnvironments.kt @@ -38,7 +38,7 @@ import com.squareup.workflow.ui.compose.internal.showRendering * val child: Any * ) * - * val FramedContainerViewFactory = bindCompose { rendering, environment -> + * val FramedContainerViewFactory = composedViewFactory { rendering, environment -> * Surface(border = Border(rendering.borderColor, 8.dp)) { * environment.showRendering(rendering.child) * } diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ParentComposition.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ParentComposition.kt index 633530e8..3b205fbc 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ParentComposition.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ParentComposition.kt @@ -68,11 +68,11 @@ internal fun ViewGroup.setOrSubcomposeContent( content: @Composable() () -> Unit ) { if (parentComposition != null) { - // Somewhere above us in the workflow rendering tree, there's another bindCompose factory. + // Somewhere above us in the workflow rendering tree, there's another composedViewFactory. // We need to link to its composition reference so we inherit its ambients. setContent(Recomposer.current(), parentComposition, content) } else { - // This is the first bindCompose factory in the rendering tree, so it won't be a child + // This is the first composedViewFactory in the rendering tree, so it won't be a child // composition. setContent(Recomposer.current(), content) } diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewFactories.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewFactories.kt index 70048c41..db33eb55 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewFactories.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewFactories.kt @@ -38,7 +38,8 @@ import com.squareup.workflow.ui.showRendering * Renders [rendering] into the composition using the `ViewRegistry` from the [ViewEnvironment] to * determine how to draw it. * - * To display a nested rendering from a [Composable view binding][bindCompose], use + * To display a nested rendering from a + * [Composable view binding][com.squareup.workflow.ui.compose.composedViewFactory], use * [ViewEnvironment.showRendering]. * * *Note: [rendering] must be the same type as this [ViewFactory], even though the type system does diff --git a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewRegistries.kt b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewRegistries.kt index 80f6f2aa..15511c93 100644 --- a/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewRegistries.kt +++ b/core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewRegistries.kt @@ -25,7 +25,7 @@ import com.squareup.workflow.ui.ViewRegistry /** * Renders [rendering] into the composition using this [ViewRegistry] to determine how to draw it. * - * To display a nested rendering from a [Composable view binding][bindCompose], use + * To display a nested rendering from a [Composable view binding][composedViewFactory], use * [ViewEnvironment.showRendering]. * * @see ViewEnvironment.showRendering diff --git a/samples/hello-compose-binding/src/main/java/com/squareup/sample/hellocomposebinding/HelloBinding.kt b/samples/hello-compose-binding/src/main/java/com/squareup/sample/hellocomposebinding/HelloBinding.kt index 1f06ed11..f51613ab 100644 --- a/samples/hello-compose-binding/src/main/java/com/squareup/sample/hellocomposebinding/HelloBinding.kt +++ b/samples/hello-compose-binding/src/main/java/com/squareup/sample/hellocomposebinding/HelloBinding.kt @@ -25,10 +25,10 @@ import androidx.ui.layout.wrapContentSize import androidx.ui.material.ripple.ripple import androidx.ui.tooling.preview.Preview import com.squareup.sample.hellocomposebinding.HelloWorkflow.Rendering -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory import com.squareup.workflow.ui.compose.tooling.preview -val HelloBinding = bindCompose { rendering, _ -> +val HelloBinding = composedViewFactory { rendering, _ -> Clickable( modifier = Modifier.fillMaxSize() .ripple(bounded = true), diff --git a/samples/hello-compose/src/main/java/com/squareup/sample/hellocompose/HelloBinding.kt b/samples/hello-compose/src/main/java/com/squareup/sample/hellocompose/HelloBinding.kt index 277c0590..57d19a87 100644 --- a/samples/hello-compose/src/main/java/com/squareup/sample/hellocompose/HelloBinding.kt +++ b/samples/hello-compose/src/main/java/com/squareup/sample/hellocompose/HelloBinding.kt @@ -23,9 +23,9 @@ import androidx.ui.layout.fillMaxSize import androidx.ui.layout.wrapContentSize import androidx.ui.material.ripple.ripple import com.squareup.sample.hellocompose.HelloWorkflow.Rendering -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory -val HelloBinding = bindCompose { rendering, _ -> +val HelloBinding = composedViewFactory { rendering, _ -> Clickable( onClick = { rendering.onClick() }, modifier = Modifier.ripple(bounded = true) diff --git a/samples/nested-renderings/src/main/java/com/squareup/sample/nestedrenderings/RecursiveViewFactory.kt b/samples/nested-renderings/src/main/java/com/squareup/sample/nestedrenderings/RecursiveViewFactory.kt index 48bbd88d..54b078a2 100644 --- a/samples/nested-renderings/src/main/java/com/squareup/sample/nestedrenderings/RecursiveViewFactory.kt +++ b/samples/nested-renderings/src/main/java/com/squareup/sample/nestedrenderings/RecursiveViewFactory.kt @@ -39,7 +39,7 @@ import androidx.ui.res.dimensionResource import androidx.ui.tooling.preview.Preview import com.squareup.sample.nestedrenderings.RecursiveWorkflow.Rendering import com.squareup.workflow.ui.ViewEnvironment -import com.squareup.workflow.ui.compose.bindCompose +import com.squareup.workflow.ui.compose.composedViewFactory import com.squareup.workflow.ui.compose.showRendering import com.squareup.workflow.ui.compose.tooling.preview @@ -51,7 +51,7 @@ val BackgroundColorAmbient = ambientOf { error("No background color speci /** * A `ViewFactory` that renders [RecursiveWorkflow.Rendering]s. */ -val RecursiveViewFactory = bindCompose { rendering, viewEnvironment -> +val RecursiveViewFactory = composedViewFactory { rendering, viewEnvironment -> // Every child should be drawn with a slightly-darker background color. val color = BackgroundColorAmbient.current val childColor = remember(color) {