Skip to content

Commit 1e9de52

Browse files
committed
Renames Workflow.run() to take(), improves kdoc.
1 parent 23488af commit 1e9de52

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloWorkflowFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HelloWorkflowFragment : Fragment() {
2626
val model: HelloViewModel = ViewModelProvider(this).get(HelloViewModel::class.java)
2727

2828
return WorkflowLayout(inflater.context).apply {
29-
run(model.renderings)
29+
take(model.renderings)
3030
}
3131
}
3232
}

samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloWorkflowActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HelloWorkflowActivity : AppCompatActivity() {
2121
// succeeding calls.
2222
val model: HelloViewModel by viewModels()
2323
setContentView(
24-
WorkflowLayout(this).apply { run(model.renderings) }
24+
WorkflowLayout(this).apply { take(model.renderings) }
2525
)
2626
}
2727
}

samples/stub-visibility/src/main/java/com/squareup/sample/stubvisibility/StubVisibilityActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class StubVisibilityActivity : AppCompatActivity() {
2020

2121
val model: StubVisibilityModel by viewModels()
2222
setContentView(
23-
WorkflowLayout(this).apply { run(model.renderings) }
23+
WorkflowLayout(this).apply { take(model.renderings) }
2424
)
2525
}
2626
}

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/WorkflowLayout.kt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,48 @@ public class WorkflowLayout(
4848
private var restoredChildState: SparseArray<Parcelable>? = null
4949

5050
/**
51-
* Subscribes to [renderings], and uses a [WorkflowLayout] to display its values.
51+
* Subscribes to [renderings] and display its values.
52+
*
5253
* To configure the [ViewEnvironment], e.g. to customize the UI via [ViewRegistry] entries,
53-
* use [RootScreen] as your rendering type.
54+
* use [RootScreen] as your rendering type. e.g.
55+
*
56+
* val registry = ViewRegistry(MuchBetterViewForFooScreen)
57+
* val env = ViewEnvironment(mapOf(ViewRegistry to registry))
58+
* val renderings = renderWorkflowIn(...).map { RootScreen(it, env) }
59+
* workflowLayout.take(renderings)
5460
*/
55-
public fun run(renderings: Flow<Screen>) {
61+
public fun take(renderings: Flow<Screen>) {
5662
takeWhileAttached(renderings.map { it.asRoot() }) { show(it) }
5763
}
5864

59-
@Suppress("DEPRECATION")
60-
@Deprecated("Use run()", ReplaceWith("go(renderings)"))
65+
@Deprecated(
66+
"Use take()",
67+
ReplaceWith(
68+
"take(renderings.map { " +
69+
"RootScreen(asScreen(it), ViewEnvironment(mapOf(ViewRegistry to registry))) " +
70+
"})",
71+
"com.squareup.workflow1.ui.AsScreen.Companion.asScreen",
72+
"com.squareup.workflow1.ui.ViewEnvironment",
73+
"com.squareup.workflow1.ui.ViewRegistry",
74+
"com.squareup.workflow1.ui.container.RootScreen",
75+
"kotlinx.coroutines.flow.map"
76+
)
77+
)
6178
public fun start(
6279
renderings: Flow<Any>,
6380
registry: ViewRegistry
6481
) {
82+
@Suppress("DEPRECATION")
6583
start(renderings, ViewEnvironment(mapOf(ViewRegistry to registry)))
6684
}
6785

68-
@Deprecated("Use run()", ReplaceWith("run(renderings)"))
86+
@Deprecated("Use take()", ReplaceWith("take(renderings)"))
6987
public fun start(
7088
renderings: Flow<Any>,
7189
environment: ViewEnvironment = ViewEnvironment()
7290
) {
7391
takeWhileAttached(renderings) {
92+
@Suppress("DEPRECATION")
7493
show(AsScreen.asScreen(it).asRoot() + environment)
7594
}
7695
}

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/AsScreen.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.workflow1.ui
24

5+
/**
6+
* Provides backward compatibility for non-[Screen] renderings based on
7+
* `ViewFactory` and `AndroidViewRendering`.
8+
*/
9+
@Deprecated("Implement Screen directly.")
310
@WorkflowUiExperimentalApi
411
public class AsScreen<W : Any>(
512
public val rendering: W
@@ -15,8 +22,9 @@ public class AsScreen<W : Any>(
1522

1623
public companion object {
1724
/**
18-
* Transforms [rendering] to implement [Screen], wrapping it in an [AsScreen] if necessary.
25+
* Ensures [rendering] implements [Screen], wrapping it in an [AsScreen] if necessary.
1926
*/
27+
@Deprecated("Implement Screen directly.")
2028
public fun asScreen(rendering: Any): Screen {
2129
return when (rendering) {
2230
is Screen -> rendering

0 commit comments

Comments
 (0)