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

Commit a23b56e

Browse files
Merge pull request #35 from square/zachklipp/composedviewfactory
Rename bindCompose to composedViewFactory.
2 parents dc194c3 + 3bb2f1f commit a23b56e

File tree

16 files changed

+40
-39
lines changed

16 files changed

+40
-39
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
6262
}
6363
```
6464

65-
To create a `ViewFactory`, call `bindCompose`. The lambda passed to `bindCompose` is a `@Composable`
66-
function.
65+
To create a `ViewFactory`, call `composedViewFactory`. The lambda passed to `composedViewFactory` is
66+
a `@Composable` function.
6767

6868
```kotlin
69-
val HelloBinding = bindCompose<MyRendering> { rendering, _ ->
69+
val HelloBinding = composedViewFactory<MyRendering> { rendering, _ ->
7070
MaterialTheme {
7171
Clickable(onClick = { rendering.onClick() }) {
7272
Text(rendering.message)
@@ -75,7 +75,7 @@ val HelloBinding = bindCompose<MyRendering> { rendering, _ ->
7575
}
7676
```
7777

78-
The `bindCompose` function returns a regular [`ViewFactory`][2] which can be added to a
78+
The `composedViewFactory` function returns a regular [`ViewFactory`][2] which can be added to a
7979
[`ViewRegistry`][3] like any other:
8080

8181
```kotlin

compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import androidx.ui.test.findByText
3131
import androidx.ui.tooling.preview.Preview
3232
import androidx.ui.unit.dp
3333
import com.squareup.workflow.ui.ViewEnvironmentKey
34-
import com.squareup.workflow.ui.compose.bindCompose
34+
import com.squareup.workflow.ui.compose.composedViewFactory
3535
import com.squareup.workflow.ui.compose.showRendering
3636
import org.junit.Rule
3737
import org.junit.Test
@@ -99,7 +99,7 @@ class PreviewViewFactoryTest {
9999
findByText("foo").assertIsDisplayed()
100100
}
101101

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

115115
private val ParentWithTwoChildren =
116-
bindCompose<Triple<String, String, String>> { rendering, environment ->
116+
composedViewFactory<Triple<String, String, String>> { rendering, environment ->
117117
Column {
118118
Semantics(container = true) {
119119
environment.showRendering(rendering = rendering.first)
@@ -134,7 +134,7 @@ class PreviewViewFactoryTest {
134134
val child: RecursiveRendering? = null
135135
)
136136

137-
private val ParentRecursive = bindCompose<RecursiveRendering> { rendering, environment ->
137+
private val ParentRecursive = composedViewFactory<RecursiveRendering> { rendering, environment ->
138138
Column {
139139
Text(rendering.text)
140140
rendering.child?.let { child ->
@@ -175,7 +175,7 @@ class PreviewViewFactoryTest {
175175
override val default: String get() = error("Not specified")
176176
}
177177

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

compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ import androidx.ui.unit.dp
4242
import androidx.ui.unit.px
4343
import androidx.ui.unit.toRect
4444
import com.squareup.workflow.ui.ViewFactory
45-
import com.squareup.workflow.ui.compose.bindCompose
45+
import com.squareup.workflow.ui.compose.composedViewFactory
4646

4747
/**
4848
* A [ViewFactory] that will be used any time a [PreviewViewRegistry] is asked to show a rendering.
4949
* It displays a placeholder graphic and the rendering's `toString()` result.
5050
*/
5151
internal fun placeholderViewFactory(modifier: Modifier): ViewFactory<Any> =
52-
bindCompose { rendering, _ ->
52+
composedViewFactory { rendering, _ ->
5353
Text(
5454
modifier = modifier
5555
.clipToBounds()

core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/ComposeViewFactoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ComposeViewFactoryTest {
7171
private data class TestRendering(val text: String)
7272

7373
private companion object {
74-
val TestFactory = bindCompose<TestRendering> { rendering, _ ->
74+
val TestFactory = composedViewFactory<TestRendering> { rendering, _ ->
7575
Text(rendering.text)
7676
}
7777
}

core-compose/src/androidTest/java/com/squareup/workflow/ui/compose/internal/ViewFactoriesTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import androidx.ui.test.createComposeRule
2323
import androidx.ui.test.findByText
2424
import com.squareup.workflow.ui.ViewEnvironment
2525
import com.squareup.workflow.ui.ViewRegistry
26-
import com.squareup.workflow.ui.compose.bindCompose
26+
import com.squareup.workflow.ui.compose.composedViewFactory
2727
import com.squareup.workflow.ui.compose.showRendering
2828
import com.squareup.workflow.ui.compose.withComposeViewFactoryRoot
2929
import org.junit.Rule
@@ -54,7 +54,7 @@ class ViewFactoriesTest {
5454
private data class TestRendering(val text: String)
5555

5656
private companion object {
57-
val TestFactory = bindCompose<TestRendering> { rendering, _ ->
57+
val TestFactory = composedViewFactory<TestRendering> { rendering, _ ->
5858
Text(rendering.text)
5959
}
6060
}

core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeRendering.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ComposeRendering internal constructor(
3838
/**
3939
* A [ViewFactory] that renders a [ComposeRendering].
4040
*/
41-
val Factory: ViewFactory<ComposeRendering> = bindCompose { rendering, environment ->
41+
val Factory: ViewFactory<ComposeRendering> = composedViewFactory { rendering, environment ->
4242
rendering.render(environment)
4343
}
4444

core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import kotlin.reflect.KClass
4343
*
4444
* ```
4545
* // Function references to @Composable functions aren't supported yet.
46-
* val FooBinding = bindCompose { showFoo(it) }
46+
* val FooBinding = composedViewFactory { showFoo(it) }
4747
*
4848
* @Composable
4949
* private fun showFoo(foo: FooRendering) {
@@ -73,14 +73,14 @@ import kotlin.reflect.KClass
7373
*
7474
* ## Initializing Compose context
7575
*
76-
* Often all the [bindCompose] factories in an app need to share some context – for example, certain
76+
* Often all the [composedViewFactory]s in an app need to share some context – for example, certain
7777
* ambients need to be provided, such as `MaterialTheme`. To configure this shared context, include
7878
* a [ComposeViewFactoryRoot] in your top-level [ViewEnvironment] (e.g. by using
79-
* [withComposeViewFactoryRoot]). The first time a [bindCompose] is used to show a rendering, its
80-
* [showRendering] function will be wrapped with the [ComposeViewFactoryRoot]. See the documentation
81-
* on [ComposeViewFactoryRoot] for more information.
79+
* [withComposeViewFactoryRoot]). The first time a [composedViewFactory] is used to show a
80+
* rendering, its [showRendering] function will be wrapped with the [ComposeViewFactoryRoot].
81+
* See the documentation on [ComposeViewFactoryRoot] for more information.
8282
*/
83-
inline fun <reified RenderingT : Any> bindCompose(
83+
inline fun <reified RenderingT : Any> composedViewFactory(
8484
noinline showRendering: @Composable() (
8585
rendering: RenderingT,
8686
environment: ViewEnvironment

core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactoryRoot.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ private val HasViewFactoryRootBeenApplied = staticAmbientOf { false }
3333

3434
/**
3535
* A `@Composable` function that is stored in a [ViewEnvironment] and will be used to wrap the first
36-
* [bindCompose] composition. This can be used to setup any ambients that all [bindCompose]
37-
* factories need access to, such as ambients that specify the UI theme.
36+
* [composedViewFactory] composition. This can be used to setup any ambients that all
37+
* [composedViewFactory]s need access to, such as ambients that specify the UI theme.
3838
*
39-
* This function will called once, to wrap the _highest-level_ [bindCompose] in the tree. However,
40-
* ambients are propagated down to child [bindCompose] compositions, so any ambients provided here
41-
* will be available in _all_ [bindCompose] compositions.
39+
* This function will called once, to wrap the _highest-level_ [composedViewFactory] in the tree.
40+
* However, ambients are propagated down to child [composedViewFactory] compositions, so any
41+
* ambients provided here will be available in _all_ [composedViewFactory] compositions.
4242
*/
4343
interface ComposeViewFactoryRoot {
4444

@@ -51,7 +51,7 @@ interface ComposeViewFactoryRoot {
5151

5252
/**
5353
* Adds a [ComposeViewFactoryRoot] to this [ViewEnvironment] that uses [wrapper] to wrap the first
54-
* [bindCompose] composition. See [ComposeViewFactoryRoot] for more information.
54+
* [composedViewFactory] composition. See [ComposeViewFactoryRoot] for more information.
5555
*/
5656
fun ViewEnvironment.withComposeViewFactoryRoot(
5757
wrapper: @Composable() (content: @Composable() () -> Unit) -> Unit

core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.squareup.workflow.ui.compose.internal.ComposeWorkflowImpl
2727
/**
2828
* A stateless [Workflow][com.squareup.workflow.Workflow] that [renders][render] itself as
2929
* [Composable] function. Effectively defines an inline
30-
* [bindCompose][com.squareup.workflow.ui.compose.bindCompose].
30+
* [composedViewFactory][com.squareup.workflow.ui.compose.composedViewFactory].
3131
*
3232
* This workflow does not have access to a [RenderContext][com.squareup.workflow.RenderContext]
3333
* since render contexts are only valid during render passes, and this workflow's [render] method

core-compose/src/main/java/com/squareup/workflow/ui/compose/ViewEnvironments.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import com.squareup.workflow.ui.compose.internal.showRendering
3838
* val child: Any
3939
* )
4040
*
41-
* val FramedContainerViewFactory = bindCompose<FramedRendering> { rendering, environment ->
41+
* val FramedContainerViewFactory = composedViewFactory<FramedRendering> { rendering, environment ->
4242
* Surface(border = Border(rendering.borderColor, 8.dp)) {
4343
* environment.showRendering(rendering.child)
4444
* }

0 commit comments

Comments
 (0)