Skip to content

Commit 226bf2f

Browse files
committed
No more hard coded EnvironmentScreen in WorkflowLayout.
WorkflowLayout was wrapping things in EnvironmentScreen for no real reason. No longer.
1 parent a068026 commit 226bf2f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

workflow-ui/core-android/api/core-android.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ public abstract interface class com/squareup/workflow1/ui/ViewStarter {
293293
public final class com/squareup/workflow1/ui/WorkflowLayout : android/widget/FrameLayout {
294294
public fun <init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
295295
public synthetic fun <init> (Landroid/content/Context;Landroid/util/AttributeSet;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
296-
public final fun show (Lcom/squareup/workflow1/ui/Screen;)V
296+
public final fun show (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)V
297+
public static synthetic fun show$default (Lcom/squareup/workflow1/ui/WorkflowLayout;Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)V
297298
public final fun start (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Landroidx/lifecycle/Lifecycle$State;Lcom/squareup/workflow1/ui/ViewEnvironment;)V
298299
public final fun start (Landroidx/lifecycle/Lifecycle;Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewRegistry;)V
299300
public final fun start (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/ui/ViewEnvironment;)V

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import androidx.lifecycle.Lifecycle.State
1515
import androidx.lifecycle.Lifecycle.State.STARTED
1616
import androidx.lifecycle.coroutineScope
1717
import androidx.lifecycle.repeatOnLifecycle
18-
import com.squareup.workflow1.ui.container.EnvironmentScreen
19-
import com.squareup.workflow1.ui.container.withEnvironment
2018
import kotlinx.coroutines.CoroutineScope
2119
import kotlinx.coroutines.Dispatchers
2220
import kotlinx.coroutines.Job
@@ -28,7 +26,9 @@ import kotlinx.coroutines.launch
2826

2927
/**
3028
* A view that can be driven by a stream of [Screen] renderings passed to its [take] method.
31-
* To configure the [ViewEnvironment] in play, use [EnvironmentScreen] as your root rendering type.
29+
*
30+
* Suitable for use as the content view of an [Activity][android.app.Activity.setContentView],
31+
* or [Fragment][androidx.fragment.app.Fragment.onCreateView].
3232
*
3333
* [id][setId] defaults to [R.id.workflow_layout], as a convenience to ensure that
3434
* view persistence will work without requiring authors to be immersed in Android arcana.
@@ -60,8 +60,11 @@ public class WorkflowLayout(
6060
* [take] than to call this method directly. It is exposed to allow clients to
6161
* make their own choices about how exactly to consume a stream of renderings.
6262
*/
63-
public fun show(rootScreen: Screen) {
64-
showing.show(rootScreen, rootScreen.withEnvironment().environment)
63+
public fun show(
64+
rootScreen: Screen,
65+
environment: ViewEnvironment = ViewEnvironment.EMPTY
66+
) {
67+
showing.show(rootScreen, environment)
6568
restoredChildState?.let { restoredState ->
6669
restoredChildState = null
6770
showing.actual.restoreHierarchyState(restoredState)
@@ -72,6 +75,12 @@ public class WorkflowLayout(
7275
* This is the most common way to bootstrap a [Workflow][com.squareup.workflow1.Workflow]
7376
* driven UI. Collects [renderings] and calls [show] with each one.
7477
*
78+
* To configure a root [ViewEnvironment], use
79+
* [EnvironmentScreen][com.squareup.workflow1.ui.container.EnvironmentScreen] as your
80+
* root rendering type, perhaps via
81+
* [withEnvironment][com.squareup.workflow1.ui.container.withEnvironment] or
82+
* [withRegistry][com.squareup.workflow1.ui.container.withRegistry].
83+
*
7584
* @param [lifecycle] the lifecycle that defines when and how this view should be updated.
7685
* Typically this comes from `ComponentActivity.lifecycle` or `Fragment.lifecycle`.
7786
* @param [repeatOnLifecycle] the lifecycle state in which renderings should be actively
@@ -85,7 +94,7 @@ public class WorkflowLayout(
8594
// Just like https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda
8695
lifecycle.coroutineScope.launch {
8796
lifecycle.repeatOnLifecycle(repeatOnLifecycle) {
88-
renderings.collect { show(it.withEnvironment()) }
97+
renderings.collect { show(it) }
8998
}
9099
}
91100
}
@@ -127,7 +136,7 @@ public class WorkflowLayout(
127136
public fun start(
128137
lifecycle: Lifecycle,
129138
renderings: Flow<Any>,
130-
repeatOnLifecycle: Lifecycle.State = Lifecycle.State.STARTED,
139+
repeatOnLifecycle: State = STARTED,
131140
environment: ViewEnvironment = ViewEnvironment.EMPTY
132141
) {
133142
// Just like https://medium.com/androiddevelopers/a-safer-way-to-collect-flows-from-android-uis-23080b1f8bda

0 commit comments

Comments
 (0)