Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Rename bindCompose to composedViewFactory. #35

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyRendering> { rendering, _ ->
val HelloBinding = composedViewFactory<MyRendering> { rendering, _ ->
MaterialTheme {
Clickable(onClick = { rendering.onClick() }) {
Text(rendering.message)
Expand All @@ -75,7 +75,7 @@ val HelloBinding = bindCompose<MyRendering> { 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,7 +99,7 @@ class PreviewViewFactoryTest {
findByText("foo").assertIsDisplayed()
}

private val ParentWithOneChild = bindCompose<Pair<String, String>> { rendering, environment ->
private val ParentWithOneChild = composedViewFactory<Pair<String, String>> { rendering, environment ->
Column {
Text(rendering.first)
Semantics(container = true, mergeAllDescendants = true) {
Expand All @@ -113,7 +113,7 @@ class PreviewViewFactoryTest {
}

private val ParentWithTwoChildren =
bindCompose<Triple<String, String, String>> { rendering, environment ->
composedViewFactory<Triple<String, String, String>> { rendering, environment ->
Column {
Semantics(container = true) {
environment.showRendering(rendering = rendering.first)
Expand All @@ -134,7 +134,7 @@ class PreviewViewFactoryTest {
val child: RecursiveRendering? = null
)

private val ParentRecursive = bindCompose<RecursiveRendering> { rendering, environment ->
private val ParentRecursive = composedViewFactory<RecursiveRendering> { rendering, environment ->
Column {
Text(rendering.text)
rendering.child?.let { child ->
Expand Down Expand Up @@ -175,7 +175,7 @@ class PreviewViewFactoryTest {
override val default: String get() = error("Not specified")
}

private val ParentConsumesCustomKey = bindCompose<Unit> { _, environment ->
private val ParentConsumesCustomKey = composedViewFactory<Unit> { _, environment ->
Text(environment[TestEnvironmentKey])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any> =
bindCompose { rendering, _ ->
composedViewFactory { rendering, _ ->
Text(
modifier = modifier
.clipToBounds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ComposeViewFactoryTest {
private data class TestRendering(val text: String)

private companion object {
val TestFactory = bindCompose<TestRendering> { rendering, _ ->
val TestFactory = composedViewFactory<TestRendering> { rendering, _ ->
Text(rendering.text)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,7 +54,7 @@ class ViewFactoriesTest {
private data class TestRendering(val text: String)

private companion object {
val TestFactory = bindCompose<TestRendering> { rendering, _ ->
val TestFactory = composedViewFactory<TestRendering> { rendering, _ ->
Text(rendering.text)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ComposeRendering internal constructor(
/**
* A [ViewFactory] that renders a [ComposeRendering].
*/
val Factory: ViewFactory<ComposeRendering> = bindCompose { rendering, environment ->
val Factory: ViewFactory<ComposeRendering> = composedViewFactory { rendering, environment ->
rendering.render(environment)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <reified RenderingT : Any> bindCompose(
inline fun <reified RenderingT : Any> composedViewFactory(
noinline showRendering: @Composable() (
rendering: RenderingT,
environment: ViewEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.squareup.workflow.ui.compose.internal.showRendering
* val child: Any
* )
*
* val FramedContainerViewFactory = bindCompose<FramedRendering> { rendering, environment ->
* val FramedContainerViewFactory = composedViewFactory<FramedRendering> { rendering, environment ->
* Surface(border = Border(rendering.borderColor, 8.dp)) {
* environment.showRendering(rendering.child)
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> { rendering, _ ->
val HelloBinding = composedViewFactory<Rendering> { rendering, _ ->
Clickable(
modifier = Modifier.fillMaxSize()
.ripple(bounded = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> { rendering, _ ->
val HelloBinding = composedViewFactory<Rendering> { rendering, _ ->
Clickable(
onClick = { rendering.onClick() },
modifier = Modifier.ripple(bounded = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -51,7 +51,7 @@ val BackgroundColorAmbient = ambientOf<Color> { error("No background color speci
/**
* A `ViewFactory` that renders [RecursiveWorkflow.Rendering]s.
*/
val RecursiveViewFactory = bindCompose<Rendering> { rendering, viewEnvironment ->
val RecursiveViewFactory = composedViewFactory<Rendering> { rendering, viewEnvironment ->
// Every child should be drawn with a slightly-darker background color.
val color = BackgroundColorAmbient.current
val childColor = remember(color) {
Expand Down