Skip to content

Commit ad1a88a

Browse files
committed
Revert "Simpler, safer ViewEnvironment and ViewRegistry management."
This reverts commit 85ff181. It was unreviewed and untested, accidental merge.
1 parent a608127 commit ad1a88a

File tree

36 files changed

+199
-387
lines changed

36 files changed

+199
-387
lines changed

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/App.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import com.squareup.workflow1.ui.ViewRegistry
1616
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1717
import com.squareup.workflow1.ui.compose.WorkflowRendering
1818
import com.squareup.workflow1.ui.compose.renderAsState
19-
import com.squareup.workflow1.ui.plus
2019

21-
private val viewEnvironment = ViewEnvironment.EMPTY + ViewRegistry(HelloBinding)
20+
private val viewRegistry = ViewRegistry(HelloBinding)
21+
22+
private val viewEnvironment = ViewEnvironment(mapOf(ViewRegistry to viewRegistry))
2223

2324
@Composable fun App() {
2425
MaterialTheme {

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import com.squareup.workflow1.ui.WorkflowLayout
1515
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1616
import com.squareup.workflow1.ui.compose.composeViewFactory
1717
import com.squareup.workflow1.ui.compose.withCompositionRoot
18-
import com.squareup.workflow1.ui.plus
1918
import com.squareup.workflow1.ui.renderWorkflowIn
2019
import kotlinx.coroutines.flow.StateFlow
2120

21+
@OptIn(WorkflowUiExperimentalApi::class)
22+
private val viewRegistry = ViewRegistry(HelloBinding)
23+
2224
@OptIn(WorkflowUiExperimentalApi::class)
2325
private val viewEnvironment =
24-
(ViewEnvironment.EMPTY + ViewRegistry(HelloBinding)).withCompositionRoot { content ->
26+
ViewEnvironment(mapOf(ViewRegistry to viewRegistry)).withCompositionRoot { content ->
2527
MaterialTheme(content = content)
2628
}
2729

@@ -35,22 +37,22 @@ class HelloBindingActivity : AppCompatActivity() {
3537

3638
val model: HelloBindingModel by viewModels()
3739
setContentView(
38-
WorkflowLayout(this).apply {
39-
start(
40-
renderings = model.renderings,
41-
environment = viewEnvironment
42-
)
43-
}
40+
WorkflowLayout(this).apply {
41+
start(
42+
renderings = model.renderings,
43+
environment = viewEnvironment
44+
)
45+
}
4446
)
4547
}
4648

4749
class HelloBindingModel(savedState: SavedStateHandle) : ViewModel() {
4850
@OptIn(WorkflowUiExperimentalApi::class)
4951
val renderings: StateFlow<Any> by lazy {
5052
renderWorkflowIn(
51-
workflow = HelloWorkflow,
52-
scope = viewModelScope,
53-
savedStateHandle = savedState
53+
workflow = HelloWorkflow,
54+
scope = viewModelScope,
55+
savedStateHandle = savedState
5456
)
5557
}
5658
}

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ object HelloComposeWorkflow : ComposeWorkflow<String, Toggle>() {
4848
@Preview(showBackground = true)
4949
@Composable fun HelloComposeWorkflowPreview() {
5050
val rendering by HelloComposeWorkflow.renderAsState(props = "hello", onOutput = {})
51-
WorkflowRendering(rendering, ViewEnvironment.EMPTY)
51+
WorkflowRendering(rendering, ViewEnvironment())
5252
}

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, AndroidVie
5555
@Preview
5656
@Composable fun InlineRenderingWorkflowPreview() {
5757
val rendering by InlineRenderingWorkflow.renderAsState(props = Unit, onOutput = {})
58-
WorkflowRendering(rendering, ViewEnvironment.EMPTY)
58+
WorkflowRendering(rendering, ViewEnvironment())
5959
}
6060

6161
@OptIn(ExperimentalAnimationApi::class)

samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.squareup.workflow1.ui.ViewRegistry
1515
import com.squareup.workflow1.ui.WorkflowLayout
1616
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1717
import com.squareup.workflow1.ui.compose.withCompositionRoot
18-
import com.squareup.workflow1.ui.plus
1918
import com.squareup.workflow1.ui.renderWorkflowIn
2019
import kotlinx.coroutines.flow.StateFlow
2120

@@ -27,7 +26,7 @@ private val viewRegistry = ViewRegistry(
2726

2827
@OptIn(WorkflowUiExperimentalApi::class)
2928
private val viewEnvironment =
30-
(ViewEnvironment.EMPTY + viewRegistry).withCompositionRoot { content ->
29+
ViewEnvironment(mapOf(ViewRegistry to viewRegistry)).withCompositionRoot { content ->
3130
CompositionLocalProvider(LocalBackgroundColor provides Color.Green) {
3231
content()
3332
}

samples/compose-samples/src/main/java/com/squareup/sample/compose/textinput/App.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@file:OptIn(WorkflowUiExperimentalApi::class)
2-
@file:Suppress("FunctionName")
32

43
package com.squareup.sample.compose.textinput
54

@@ -12,9 +11,10 @@ import com.squareup.workflow1.ui.ViewRegistry
1211
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1312
import com.squareup.workflow1.ui.compose.WorkflowRendering
1413
import com.squareup.workflow1.ui.compose.renderAsState
15-
import com.squareup.workflow1.ui.plus
1614

17-
private val viewEnvironment = ViewEnvironment.EMPTY + ViewRegistry(TextInputViewFactory)
15+
private val viewRegistry = ViewRegistry(TextInputViewFactory)
16+
17+
private val viewEnvironment = ViewEnvironment(mapOf(ViewRegistry to viewRegistry))
1818

1919
@Composable fun TextInputApp() {
2020
MaterialTheme {

samples/containers/android/src/main/java/com/squareup/sample/container/overviewdetail/OverviewDetailConfig.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.squareup.sample.container.overviewdetail
22

3-
import com.squareup.workflow1.ui.ViewEnvironment
4-
import com.squareup.workflow1.ui.ViewEnvironmentKey
53
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
4+
import com.squareup.workflow1.ui.ViewEnvironmentKey
65

76
/**
87
* [com.squareup.workflow1.ui.ViewEnvironment] value that informs views
@@ -35,7 +34,3 @@ enum class OverviewDetailConfig {
3534
override val default = None
3635
}
3736
}
38-
39-
@WorkflowUiExperimentalApi
40-
operator fun ViewEnvironment.plus(config: OverviewDetailConfig): ViewEnvironment =
41-
this + (OverviewDetailConfig to config)

samples/containers/android/src/main/java/com/squareup/sample/container/overviewdetail/OverviewDetailContainer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ class OverviewDetailContainer(view: View) : ScreenViewRunner<OverviewDetailScree
5656
// Since we have two sibling back stacks, we need to give them each different
5757
// SavedStateRegistry key prefixes.
5858
val overviewViewEnvironment = viewEnvironment
59-
.withBackStackStateKeyPrefix(OverviewBackStackKey) + Overview
59+
.withBackStackStateKeyPrefix(OverviewBackStackKey) + (OverviewDetailConfig to Overview)
6060
overviewStub!!.show(rendering.overviewRendering, overviewViewEnvironment)
6161
rendering.detailRendering
6262
?.let { detail ->
6363
detailStub!!.actual.visibility = VISIBLE
6464
detailStub.show(
6565
detail,
66-
viewEnvironment + Detail
66+
viewEnvironment + (OverviewDetailConfig to Detail)
6767
)
6868
}
6969
?: run {
@@ -81,7 +81,7 @@ class OverviewDetailContainer(view: View) : ScreenViewRunner<OverviewDetailScree
8181
?.let { rendering.overviewRendering + it }
8282
?: rendering.overviewRendering
8383

84-
stub.show(combined, viewEnvironment + Single)
84+
stub.show(combined, viewEnvironment + (OverviewDetailConfig to Single))
8585
}
8686

8787
companion object : ScreenViewFactory<OverviewDetailScreen> by ScreenViewRunner.bind(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal class PreviewViewFactoryTest {
7979
composeRule.onNodeWithText("two").assertIsNotDisplayed()
8080
}
8181

82-
@Test fun customViewEnvironment.EMPTY {
82+
@Test fun customViewEnvironment() {
8383
composeRule.setContent {
8484
ParentConsumesCustomKeyPreview()
8585
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.squareup.workflow1.ui.ViewEnvironment
1111
import com.squareup.workflow1.ui.ViewFactory
1212
import com.squareup.workflow1.ui.ViewRegistry
1313
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
14-
import com.squareup.workflow1.ui.plus
1514
import kotlin.reflect.KClass
1615

1716
/**
@@ -31,7 +30,7 @@ import kotlin.reflect.KClass
3130
PreviewViewRegistry(mainFactory, placeholderViewFactory(placeholderModifier))
3231
}
3332
return remember(viewRegistry, viewEnvironmentUpdater) {
34-
(ViewEnvironment.EMPTY + viewRegistry).let { environment ->
33+
ViewEnvironment(mapOf(ViewRegistry to viewRegistry)).let { environment ->
3534
// Give the preview a chance to add its own elements to the ViewEnvironment.
3635
viewEnvironmentUpdater?.let { it(environment) } ?: environment
3736
}

0 commit comments

Comments
 (0)