diff --git a/kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/ReactorAsWorkflowIntegrationTest.kt b/kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/ReactorAsWorkflowIntegrationTest.kt index 524fcb659..221ca4d70 100644 --- a/kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/ReactorAsWorkflowIntegrationTest.kt +++ b/kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/ReactorAsWorkflowIntegrationTest.kt @@ -32,8 +32,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import org.junit.Test -import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertFalse diff --git a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt index 65e68c484..1860bb248 100644 --- a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt +++ b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt @@ -55,7 +55,7 @@ data class BackButtonScreen( .also { view -> val wrappedUpdater = view.getShowRendering()!! - view.bindShowRendering(initialRendering, initialHints) { rendering, hints -> + view.bindShowRendering(initialRendering, initialHints) { rendering, environment -> if (!rendering.override) { // Place our handler before invoking the wrapped updater, so that // its later calls to view.backPressedHandler will take precedence @@ -63,7 +63,7 @@ data class BackButtonScreen( view.backPressedHandler = rendering.onBackPressed } - wrappedUpdater.invoke(rendering.wrapped, hints) + wrappedUpdater.invoke(rendering.wrapped, environment) if (rendering.override) { // Place our handler after invoking the wrapped updater, so that ours diff --git a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailConfig.kt b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailConfig.kt index 5d8b4c5cc..0b8d77328 100644 --- a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailConfig.kt +++ b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailConfig.kt @@ -15,10 +15,10 @@ */ package com.squareup.sample.container.masterdetail -import com.squareup.workflow.ui.ContainerHintKey +import com.squareup.workflow.ui.ViewEnvironmentKey /** - * [com.squareup.workflow.ui.ContainerHints] value that informs views + * [com.squareup.workflow.ui.ViewEnvironment] value that informs views * whether they're children of a [MasterDetailContainer], and if so * in what configuration. */ @@ -43,7 +43,7 @@ enum class MasterDetailConfig { */ Single; - companion object : ContainerHintKey(MasterDetailConfig::class) { + companion object : ViewEnvironmentKey(MasterDetailConfig::class) { override val default = None } } diff --git a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailContainer.kt b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailContainer.kt index 2375d928e..5a7893e99 100644 --- a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailContainer.kt +++ b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/masterdetail/MasterDetailContainer.kt @@ -22,9 +22,9 @@ import com.squareup.sample.container.R import com.squareup.sample.container.masterdetail.MasterDetailConfig.Detail import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master import com.squareup.sample.container.masterdetail.MasterDetailConfig.Single -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub import com.squareup.workflow.ui.backstack.BackStackScreen @@ -52,29 +52,29 @@ class MasterDetailContainer(view: View) : LayoutRunner { override fun showRendering( rendering: MasterDetailScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - if (singleStub == null) renderSplitView(rendering, containerHints) - else renderSingleView(rendering, containerHints, singleStub) + if (singleStub == null) renderSplitView(rendering, viewEnvironment) + else renderSingleView(rendering, viewEnvironment, singleStub) } private fun renderSplitView( rendering: MasterDetailScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { if (rendering.detailRendering == null && rendering.selectDefault != null) { rendering.selectDefault!!.invoke() } else { masterStub!!.update( rendering.masterRendering, - containerHints + (MasterDetailConfig to Master) + viewEnvironment + (MasterDetailConfig to Master) ) rendering.detailRendering ?.let { detail -> detailStub!!.actual.visibility = VISIBLE detailStub.update( detail, - containerHints + (MasterDetailConfig to Detail) + viewEnvironment + (MasterDetailConfig to Detail) ) } ?: run { @@ -85,14 +85,14 @@ class MasterDetailContainer(view: View) : LayoutRunner { private fun renderSingleView( rendering: MasterDetailScreen, - containerHints: ContainerHints, + viewEnvironment: ViewEnvironment, stub: WorkflowViewStub ) { val combined: BackStackScreen<*> = rendering.detailRendering ?.let { rendering.masterRendering + it } ?: rendering.masterRendering - stub.update(combined, containerHints + (MasterDetailConfig to Single)) + stub.update(combined, viewEnvironment + (MasterDetailConfig to Single)) } companion object : ViewBinding by LayoutRunner.Binding( diff --git a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/panel/ScrimContainer.kt b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/panel/ScrimContainer.kt index 09b911b25..38835aa55 100644 --- a/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/panel/ScrimContainer.kt +++ b/kotlin/samples/containers/android/src/main/java/com/squareup/sample/container/panel/ScrimContainer.kt @@ -113,8 +113,8 @@ class ScrimContainer @JvmOverloads constructor( layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) addView(stub) - bindShowRendering(initialRendering, initialContainerHints) { rendering, hints -> - stub.update(rendering.wrapped, hints) + bindShowRendering(initialRendering, initialContainerHints) { rendering, environment -> + stub.update(rendering.wrapped, environment) isDimmed = rendering.dimmed } } diff --git a/kotlin/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemListLayoutRunner.kt b/kotlin/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemListLayoutRunner.kt index 6e5afe8ae..82e326dcc 100644 --- a/kotlin/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemListLayoutRunner.kt +++ b/kotlin/samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoemListLayoutRunner.kt @@ -25,10 +25,10 @@ import androidx.recyclerview.widget.RecyclerView import com.squareup.sample.container.masterdetail.MasterDetailConfig import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master import com.squareup.sample.container.poetryapp.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment class PoemListLayoutRunner(view: View) : LayoutRunner { init { @@ -46,10 +46,10 @@ class PoemListLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: PoemListRendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { adapter.rendering = rendering - adapter.hints = containerHints + adapter.environment = viewEnvironment adapter.notifyDataSetChanged() if (recyclerView.adapter == null) recyclerView.adapter = adapter @@ -60,13 +60,13 @@ class PoemListLayoutRunner(view: View) : LayoutRunner { private class Adapter : RecyclerView.Adapter() { lateinit var rendering: PoemListRendering - lateinit var hints: ContainerHints + lateinit var environment: ViewEnvironment override fun onCreateViewHolder( parent: ViewGroup, viewType: Int ): ViewHolder { - val selectable = hints[MasterDetailConfig] == Master + val selectable = environment[MasterDetailConfig] == Master val layoutId = if (selectable) { R.layout.list_row_selectable } else { diff --git a/kotlin/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutRunner.kt b/kotlin/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutRunner.kt index 944f3e341..7db4c029d 100644 --- a/kotlin/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutRunner.kt +++ b/kotlin/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutRunner.kt @@ -17,13 +17,13 @@ package com.squareup.sample.hellobackbutton import android.view.View import android.widget.TextView +import com.squareup.sample.hellobackbutton.HelloBackButtonWorkflow.Rendering import com.squareup.sample.hellobackbutton.R.id import com.squareup.sample.hellobackbutton.R.layout -import com.squareup.sample.hellobackbutton.HelloBackButtonWorkflow.Rendering -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler class HelloBackButtonLayoutRunner(view: View) : LayoutRunner { @@ -31,7 +31,7 @@ class HelloBackButtonLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: Rendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { messageView.text = rendering.message messageView.setOnClickListener { rendering.onClick() } diff --git a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaLayoutRunner.kt b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaLayoutRunner.kt index 714ba3d98..2ee3f205a 100644 --- a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaLayoutRunner.kt +++ b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaLayoutRunner.kt @@ -26,9 +26,9 @@ import androidx.appcompat.widget.Toolbar import com.squareup.sample.container.masterdetail.MasterDetailConfig import com.squareup.sample.container.masterdetail.MasterDetailConfig.Detail import com.squareup.sample.container.poetry.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler import com.squareup.workflow.ui.backstack.BackStackConfig import com.squareup.workflow.ui.backstack.BackStackConfig.None @@ -47,9 +47,9 @@ class StanzaLayoutRunner(private val view: View) : LayoutRunner override fun showRendering( rendering: StanzaRendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - if (containerHints[MasterDetailConfig] == Detail) { + if (viewEnvironment[MasterDetailConfig] == Detail) { toolbar.title = "Stanza ${rendering.stanzaNumber}" toolbar.subtitle = null } else { @@ -81,14 +81,14 @@ class StanzaLayoutRunner(private val view: View) : LayoutRunner goBack.visibility = View.INVISIBLE } - if (containerHints[MasterDetailConfig] != Detail && containerHints[BackStackConfig] != None) { + if (viewEnvironment[MasterDetailConfig] != Detail && viewEnvironment[BackStackConfig] != None) { toolbar.setNavigationOnClickListener { rendering.onGoUp.invoke() } } else { toolbar.navigationIcon = null } view.backPressedHandler = rendering.onGoBack - ?: rendering.onGoUp.takeIf { containerHints[MasterDetailConfig] != Detail } + ?: rendering.onGoUp.takeIf { viewEnvironment[MasterDetailConfig] != Detail } } private fun TextView.setTabulatedText(lines: List) { diff --git a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaListLayoutRunner.kt b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaListLayoutRunner.kt index 98c22e6ec..18b62722c 100644 --- a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaListLayoutRunner.kt +++ b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaListLayoutRunner.kt @@ -25,10 +25,10 @@ import androidx.recyclerview.widget.RecyclerView import com.squareup.sample.container.masterdetail.MasterDetailConfig import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master import com.squareup.sample.container.poetry.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler import com.squareup.workflow.ui.backstack.BackStackConfig import com.squareup.workflow.ui.backstack.BackStackConfig.Other @@ -42,16 +42,16 @@ class StanzaListLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: StanzaListRendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { adapter.rendering = rendering - adapter.hints = containerHints + adapter.environment = viewEnvironment adapter.notifyDataSetChanged() if (recyclerView.adapter == null) recyclerView.adapter = adapter toolbar.title = rendering.title toolbar.subtitle = rendering.subtitle - if (containerHints[BackStackConfig] == Other) { + if (viewEnvironment[BackStackConfig] == Other) { toolbar.setNavigationOnClickListener { rendering.onExit() } toolbar.backPressedHandler = rendering.onExit } else { @@ -66,13 +66,13 @@ class StanzaListLayoutRunner(view: View) : LayoutRunner { private class Adapter : RecyclerView.Adapter() { lateinit var rendering: StanzaListRendering - lateinit var hints: ContainerHints + lateinit var environment: ViewEnvironment override fun onCreateViewHolder( parent: ViewGroup, viewType: Int ): ViewHolder { - val selectable = hints[MasterDetailConfig] == Master + val selectable = environment[MasterDetailConfig] == Master val layoutId = if (selectable) { R.layout.list_row_selectable } else { diff --git a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaWorkflow.kt b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaWorkflow.kt index ea8460d3e..7110424ee 100644 --- a/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaWorkflow.kt +++ b/kotlin/samples/containers/poetry/src/main/java/com/squareup/sample/poetry/StanzaWorkflow.kt @@ -17,8 +17,8 @@ package com.squareup.sample.poetry import com.squareup.sample.poetry.StanzaWorkflow.Output import com.squareup.sample.poetry.StanzaWorkflow.Output.CloseStanzas -import com.squareup.sample.poetry.StanzaWorkflow.Output.ShowPreviousStanza import com.squareup.sample.poetry.StanzaWorkflow.Output.ShowNextStanza +import com.squareup.sample.poetry.StanzaWorkflow.Output.ShowPreviousStanza import com.squareup.sample.poetry.StanzaWorkflow.Props import com.squareup.sample.poetry.model.Poem import com.squareup.workflow.RenderContext diff --git a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/BoardsListLayoutRunner.kt b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/BoardsListLayoutRunner.kt index b230b9b55..3b295e633 100644 --- a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/BoardsListLayoutRunner.kt +++ b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/BoardsListLayoutRunner.kt @@ -24,10 +24,10 @@ import com.squareup.cycler.Recycler import com.squareup.cycler.toDataSource import com.squareup.sample.dungeon.DungeonAppWorkflow.DisplayBoardsListScreen import com.squareup.sample.dungeon.board.Board -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub /** @@ -39,14 +39,14 @@ import com.squareup.workflow.ui.WorkflowViewStub class BoardsListLayoutRunner(rootView: View) : LayoutRunner { /** - * Used to associate a single [ContainerHints] and [DisplayBoardsListScreen.onBoardSelected] + * Used to associate a single [ViewEnvironment] and [DisplayBoardsListScreen.onBoardSelected] * event handler with every item of a [DisplayBoardsListScreen]. * * @see toDataSource */ private data class BoardItem( val board: Board, - val containerHints: ContainerHints, + val viewEnvironment: ViewEnvironment, val onClicked: () -> Unit ) @@ -66,7 +66,7 @@ class BoardsListLayoutRunner(rootView: View) : LayoutRunner = object : DataSource { override val size: Int get() = boards.size override fun get(i: Int): BoardItem = BoardItem( board = boards[i], - containerHints = containerHints, + viewEnvironment = viewEnvironment, onClicked = { onBoardSelected(i) } ) } diff --git a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameLayoutRunner.kt b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameLayoutRunner.kt index 3e186dabb..a4f6ea39d 100644 --- a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameLayoutRunner.kt +++ b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameLayoutRunner.kt @@ -24,10 +24,10 @@ import com.squareup.sample.dungeon.Direction.LEFT import com.squareup.sample.dungeon.Direction.RIGHT import com.squareup.sample.dungeon.Direction.UP import com.squareup.sample.dungeon.GameWorkflow.GameRendering -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub /** @@ -53,9 +53,9 @@ class GameLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: GameRendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - boardView.update(rendering.board, containerHints) + boardView.update(rendering.board, viewEnvironment) this.rendering = rendering // Disable the views if we don't have an event handler, e.g. when the game has finished. diff --git a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/LoadingBinding.kt b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/LoadingBinding.kt index 80e0bc9a5..1c4eed99f 100644 --- a/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/LoadingBinding.kt +++ b/kotlin/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/LoadingBinding.kt @@ -18,10 +18,10 @@ package com.squareup.sample.dungeon import android.view.View import android.widget.TextView import androidx.annotation.StringRes -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment /** * Factory function for [ViewBinding]s that show a full-screen loading indicator with some text @@ -51,7 +51,7 @@ internal class LoadingLayoutRunner( override fun showRendering( rendering: RenderingT, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { // No-op. } diff --git a/kotlin/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineLayoutRunner.kt b/kotlin/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineLayoutRunner.kt index 16c4d100c..470e1823b 100644 --- a/kotlin/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineLayoutRunner.kt +++ b/kotlin/samples/dungeon/timemachine-shakeable/src/main/java/com/squareup/sample/timemachine/shakeable/ShakeableTimeMachineLayoutRunner.kt @@ -22,10 +22,10 @@ import android.widget.TextView import androidx.constraintlayout.widget.Group import androidx.transition.TransitionManager import com.squareup.sample.timemachine.shakeable.internal.GlassFrameLayout -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub import com.squareup.workflow.ui.backPressedHandler import kotlin.time.Duration @@ -55,7 +55,7 @@ class ShakeableTimeMachineLayoutRunner( override fun showRendering( rendering: ShakeableTimeMachineRendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { // Only handle back presses explicitly if in playback mode. view.backPressedHandler = rendering.onResumeRecording.takeUnless { rendering.recording } @@ -94,7 +94,7 @@ class ShakeableTimeMachineLayoutRunner( } // Show the child screen. - childStub.update(rendering.rendering, containerHints) + childStub.update(rendering.rendering, viewEnvironment) } private fun Duration.toProgressInt(): Int = toLongMilliseconds().toInt() diff --git a/kotlin/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt b/kotlin/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt index bddc14999..c366e0104 100644 --- a/kotlin/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt +++ b/kotlin/samples/dungeon/timemachine/src/main/java/com/squareup/sample/timemachine/RecorderWorkflow.kt @@ -22,9 +22,9 @@ import com.squareup.sample.timemachine.RecorderWorkflow.Recording import com.squareup.workflow.RenderContext import com.squareup.workflow.Snapshot import com.squareup.workflow.StatefulWorkflow -import kotlin.time.TimeMark import kotlin.time.Duration import kotlin.time.ExperimentalTime +import kotlin.time.TimeMark import kotlin.time.TimeSource /** diff --git a/kotlin/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloFragmentLayoutRunner.kt b/kotlin/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloFragmentLayoutRunner.kt index 49dcd1c7a..7fb81e2a3 100644 --- a/kotlin/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloFragmentLayoutRunner.kt +++ b/kotlin/samples/hello-workflow-fragment/src/main/java/com/squareup/sample/helloworkflowfragment/HelloFragmentLayoutRunner.kt @@ -18,10 +18,10 @@ package com.squareup.sample.helloworkflowfragment import android.annotation.SuppressLint import android.view.View import android.widget.TextView -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment class HelloFragmentLayoutRunner(view: View) : LayoutRunner { private val messageView = view.findViewById(R.id.hello_message) @@ -29,7 +29,7 @@ class HelloFragmentLayoutRunner(view: View) : LayoutRunner() { - override val containerHints = ContainerHints(ViewRegistry(HelloFragmentLayoutRunner)) + override val viewEnvironment = ViewEnvironment(ViewRegistry(HelloFragmentLayoutRunner)) override fun onCreateWorkflow(): WorkflowRunner.Config { return WorkflowRunner.Config( diff --git a/kotlin/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloLayoutRunner.kt b/kotlin/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloLayoutRunner.kt index 18947af20..59e338930 100644 --- a/kotlin/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloLayoutRunner.kt +++ b/kotlin/samples/hello-workflow/src/main/java/com/squareup/sample/helloworkflow/HelloLayoutRunner.kt @@ -17,17 +17,17 @@ package com.squareup.sample.helloworkflow import android.view.View import android.widget.TextView -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment class HelloLayoutRunner(view: View) : LayoutRunner { private val messageView: TextView = view.findViewById(R.id.hello_message) override fun showRendering( rendering: HelloWorkflow.Rendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { messageView.text = rendering.message messageView.setOnClickListener { rendering.onClick() } diff --git a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/BaseScreenLayoutRunner.kt b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/BaseScreenLayoutRunner.kt index 0b8056359..4040a6398 100644 --- a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/BaseScreenLayoutRunner.kt +++ b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/BaseScreenLayoutRunner.kt @@ -21,10 +21,10 @@ import com.squareup.sample.recyclerview.AppWorkflow.BaseScreen import com.squareup.sample.recyclerview.editablelistworkflow.ListDiffMode import com.squareup.sample.recyclerview.editablelistworkflow.ListDiffMode.Asynchronous import com.squareup.sample.recyclerview.editablelistworkflow.ListDiffMode.Synchronous -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub /** @@ -42,11 +42,11 @@ class BaseScreenLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: BaseScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - val syncHints = containerHints + (ListDiffMode to Synchronous) - val asyncHints = containerHints + (ListDiffMode to Asynchronous) - noDiffListStub.update(rendering.listRendering, containerHints) + val syncHints = viewEnvironment + (ListDiffMode to Synchronous) + val asyncHints = viewEnvironment + (ListDiffMode to Asynchronous) + noDiffListStub.update(rendering.listRendering, viewEnvironment) syncListStub.update(rendering.listRendering, syncHints) asyncListStub.update(rendering.listRendering, asyncHints) addRowButton.setOnClickListener { rendering.onAddRowTapped() } diff --git a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/ChooseRowTypeViewBinding.kt b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/ChooseRowTypeViewBinding.kt index 843e543c6..23fd31158 100644 --- a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/ChooseRowTypeViewBinding.kt +++ b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/ChooseRowTypeViewBinding.kt @@ -25,8 +25,8 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.Button import android.widget.LinearLayout import com.squareup.sample.recyclerview.AppWorkflow.ChooseRowTypeScreen -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.bindShowRendering import kotlin.reflect.KClass @@ -38,7 +38,7 @@ object ChooseRowTypeViewBinding : ViewBinding { override fun buildView( initialRendering: ChooseRowTypeScreen, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { @@ -48,7 +48,7 @@ object ChooseRowTypeViewBinding : ViewBinding { val inflater = LayoutInflater.from(contextForNewView) - list.bindShowRendering(initialRendering, initialContainerHints) { rendering, _ -> + list.bindShowRendering(initialRendering, initialViewEnvironment) { rendering, _ -> list.removeAllViews() rendering.options.forEachIndexed { index, option -> val row = inflater.inflate(R.layout.new_row_type_item, list, false) as Button diff --git a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListLayoutRunner.kt b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListLayoutRunner.kt index 175908f72..9032fbec7 100644 --- a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListLayoutRunner.kt +++ b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/EditableListLayoutRunner.kt @@ -22,10 +22,10 @@ import androidx.recyclerview.widget.RecyclerView import com.squareup.sample.recyclerview.R import com.squareup.sample.recyclerview.R.id import com.squareup.sample.recyclerview.editablelistworkflow.EditableListWorkflow.Rendering -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment class EditableListLayoutRunner(view: View) : LayoutRunner { private val adapter = EditableListAdapter() @@ -41,9 +41,9 @@ class EditableListLayoutRunner(view: View) : LayoutRunner { override fun showRendering( rendering: Rendering, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - adapter.updateRendering(rendering, containerHints[ListDiffMode]) + adapter.updateRendering(rendering, viewEnvironment[ListDiffMode]) } companion object : ViewBinding by bind( diff --git a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/ListDiffMode.kt b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/ListDiffMode.kt index 764531bb0..cf7298d5d 100644 --- a/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/ListDiffMode.kt +++ b/kotlin/samples/recyclerview/src/main/java/com/squareup/sample/recyclerview/editablelistworkflow/ListDiffMode.kt @@ -15,7 +15,7 @@ */ package com.squareup.sample.recyclerview.editablelistworkflow -import com.squareup.workflow.ui.ContainerHintKey +import com.squareup.workflow.ui.ViewEnvironmentKey /** * Tells [EditableListAdapter]s how to calculate and notify updates. @@ -26,7 +26,7 @@ enum class ListDiffMode { Synchronous, Asynchronous; - companion object : ContainerHintKey(ListDiffMode::class) { + companion object : ViewEnvironmentKey(ListDiffMode::class) { override val default get() = None } } diff --git a/kotlin/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt b/kotlin/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt index 2d443184f..642fcf3cd 100644 --- a/kotlin/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt +++ b/kotlin/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt @@ -39,8 +39,8 @@ import com.squareup.sample.gameworkflow.Player import com.squareup.sample.gameworkflow.symbol import com.squareup.sample.mainactivity.MainActivity import com.squareup.sample.tictactoe.R -import com.squareup.workflow.ui.ContainerHints -import com.squareup.workflow.ui.hints +import com.squareup.workflow.ui.ViewEnvironment +import com.squareup.workflow.ui.environment import com.squareup.workflow.ui.getRendering import org.junit.After import org.junit.Before @@ -83,7 +83,7 @@ class TicTacToeEspressoTest { onView(withId(R.id.start_game)).perform(click()) - val hints = AtomicReference() + val environment = AtomicReference() // Why should I learn how to write a matcher when I can just grab the activity // and work with it directly? @@ -92,9 +92,9 @@ class TicTacToeEspressoTest { val parent = button.parent as View val rendering = parent.getRendering()!! assertThat(rendering.gameState.playing).isSameInstanceAs(Player.X) - val firstHints = parent.hints + val firstHints = parent.environment assertThat(firstHints).isNotNull() - hints.set(firstHints) + environment.set(firstHints) // Make a move. rendering.onClick(0, 0) @@ -115,7 +115,7 @@ class TicTacToeEspressoTest { val parent = button.parent as View val rendering = parent.getRendering()!! assertThat(rendering.gameState.playing).isSameInstanceAs(Player.O) - assertThat(parent.hints).isEqualTo(hints.get()) + assertThat(parent.environment).isEqualTo(environment.get()) } } diff --git a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/AuthorizingLayoutRunner.kt b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/AuthorizingLayoutRunner.kt index 392a2b937..e3a9f7dcb 100644 --- a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/AuthorizingLayoutRunner.kt +++ b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/AuthorizingLayoutRunner.kt @@ -18,17 +18,17 @@ package com.squareup.sample.authworkflow import android.view.View import android.widget.TextView import com.squareup.sample.tictactoe.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment internal class AuthorizingLayoutRunner(view: View) : LayoutRunner { private val messageView: TextView = view.findViewById(R.id.authorizing_message) override fun showRendering( rendering: AuthorizingScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { messageView.text = rendering.message } diff --git a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/LoginLayoutRunner.kt b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/LoginLayoutRunner.kt index 1f0e750b8..cfa6f2fe6 100644 --- a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/LoginLayoutRunner.kt +++ b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/LoginLayoutRunner.kt @@ -20,10 +20,10 @@ import android.widget.Button import android.widget.EditText import android.widget.TextView import com.squareup.sample.tictactoe.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler internal class LoginLayoutRunner(val view: View) : LayoutRunner { @@ -34,7 +34,7 @@ internal class LoginLayoutRunner(val view: View) : LayoutRunner { override fun showRendering( rendering: LoginScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { error.text = rendering.errorMessage diff --git a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/SecondFactorLayoutRunner.kt b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/SecondFactorLayoutRunner.kt index 1542d8559..81f09a0b3 100644 --- a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/SecondFactorLayoutRunner.kt +++ b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/authworkflow/SecondFactorLayoutRunner.kt @@ -21,10 +21,10 @@ import android.widget.EditText import android.widget.TextView import androidx.appcompat.widget.Toolbar import com.squareup.sample.tictactoe.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler internal class SecondFactorLayoutRunner( @@ -37,7 +37,7 @@ internal class SecondFactorLayoutRunner( override fun showRendering( rendering: SecondFactorScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { view.backPressedHandler = { rendering.onCancel() } toolbar.setNavigationOnClickListener { rendering.onCancel() } diff --git a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/gameworkflow/GameOverLayoutRunner.kt b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/gameworkflow/GameOverLayoutRunner.kt index 7198c767e..b7695f543 100644 --- a/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/gameworkflow/GameOverLayoutRunner.kt +++ b/kotlin/samples/tictactoe/app/src/main/java/com/squareup/sample/gameworkflow/GameOverLayoutRunner.kt @@ -26,10 +26,10 @@ import com.squareup.sample.gameworkflow.SyncState.SAVED import com.squareup.sample.gameworkflow.SyncState.SAVE_FAILED import com.squareup.sample.gameworkflow.SyncState.SAVING import com.squareup.sample.tictactoe.R -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.LayoutRunner import com.squareup.workflow.ui.LayoutRunner.Companion.bind import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.backPressedHandler internal class GameOverLayoutRunner(private val view: View) : LayoutRunner { @@ -48,7 +48,7 @@ internal class GameOverLayoutRunner(private val view: View) : LayoutRunner { @@ -31,7 +31,7 @@ internal class GamePlayLayoutRunner(private val view: View) : LayoutRunner { @@ -33,7 +33,7 @@ internal class NewGameLayoutRunner(private val view: View) : LayoutRunner { private val inflater = LayoutInflater.from(view.context) @@ -35,14 +35,14 @@ internal class TodoListsLayoutRunner(view: View) : LayoutRunner override fun showRendering( rendering: TodoListsScreen, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { for ((index, list) in rendering.lists.withIndex()) { addRow( index, list, - selectable = containerHints[MasterDetailConfig] == Master, - selected = index == rendering.selection && containerHints[MasterDetailConfig] == Master + selectable = viewEnvironment[MasterDetailConfig] == Master, + selected = index == rendering.selection && viewEnvironment[MasterDetailConfig] == Master ) { rendering.onRowClicked(index) } } pruneDeadRowsFrom(rendering.lists.size) diff --git a/kotlin/trace-encoder/src/test/java/com/squareup/tracing/TraceEncoderTest.kt b/kotlin/trace-encoder/src/test/java/com/squareup/tracing/TraceEncoderTest.kt index 818995510..405b8b0f0 100644 --- a/kotlin/trace-encoder/src/test/java/com/squareup/tracing/TraceEncoderTest.kt +++ b/kotlin/trace-encoder/src/test/java/com/squareup/tracing/TraceEncoderTest.kt @@ -20,9 +20,9 @@ import kotlinx.coroutines.runBlocking import okio.Buffer import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.time.TimeMark import kotlin.time.Duration import kotlin.time.ExperimentalTime +import kotlin.time.TimeMark import kotlin.time.microseconds @OptIn(ExperimentalTime::class) diff --git a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowDiagnosticListenerIntegrationTest.kt b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowDiagnosticListenerIntegrationTest.kt index 94203658f..2713506f2 100644 --- a/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowDiagnosticListenerIntegrationTest.kt +++ b/kotlin/workflow-runtime/src/test/java/com/squareup/workflow/internal/WorkflowDiagnosticListenerIntegrationTest.kt @@ -30,13 +30,9 @@ import com.squareup.workflow.renderChild import com.squareup.workflow.stateless import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.cancel import kotlinx.coroutines.cancelChildren import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.consumeAsFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.produceIn import kotlinx.coroutines.runBlocking import kotlinx.coroutines.yield import kotlin.properties.Delegates.observable diff --git a/kotlin/workflow-tracing/src/test/java/com/squareup/workflow/diagnostic/tracing/TracingDiagnosticListenerTest.kt b/kotlin/workflow-tracing/src/test/java/com/squareup/workflow/diagnostic/tracing/TracingDiagnosticListenerTest.kt index 354ba7b84..5157c94d2 100644 --- a/kotlin/workflow-tracing/src/test/java/com/squareup/workflow/diagnostic/tracing/TracingDiagnosticListenerTest.kt +++ b/kotlin/workflow-tracing/src/test/java/com/squareup/workflow/diagnostic/tracing/TracingDiagnosticListenerTest.kt @@ -39,9 +39,9 @@ import okio.buffer import okio.source import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.time.TimeMark import kotlin.time.Duration import kotlin.time.ExperimentalTime +import kotlin.time.TimeMark @OptIn(ExperimentalCoroutinesApi::class) class TracingDiagnosticListenerTest { diff --git a/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackConfig.kt b/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackConfig.kt index b69e88ecc..5908128b4 100644 --- a/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackConfig.kt +++ b/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackConfig.kt @@ -15,7 +15,7 @@ */ package com.squareup.workflow.ui.backstack -import com.squareup.workflow.ui.ContainerHintKey +import com.squareup.workflow.ui.ViewEnvironmentKey import com.squareup.workflow.ui.backstack.BackStackConfig.First import com.squareup.workflow.ui.backstack.BackStackConfig.Other @@ -41,7 +41,7 @@ enum class BackStackConfig { */ Other; - companion object : ContainerHintKey(BackStackConfig::class) { + companion object : ViewEnvironmentKey(BackStackConfig::class) { override val default = None } } diff --git a/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackContainer.kt b/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackContainer.kt index d12878adb..9897dd522 100644 --- a/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackContainer.kt +++ b/kotlin/workflow-ui/backstack-android/src/main/java/com/squareup/workflow/ui/backstack/BackStackContainer.kt @@ -29,9 +29,9 @@ import androidx.transition.Slide import androidx.transition.TransitionManager import androidx.transition.TransitionSet import com.squareup.workflow.ui.BuilderBinding -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.Named import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.ViewRegistry import com.squareup.workflow.ui.backstack.BackStackConfig.First import com.squareup.workflow.ui.backstack.BackStackConfig.Other @@ -58,10 +58,10 @@ open class BackStackContainer @JvmOverloads constructor( private fun update( newRendering: BackStackScreen<*>, - newContainerHints: ContainerHints + newViewEnvironment: ViewEnvironment ) { val config = if (newRendering.backStack.isEmpty()) First else Other - val hints = newContainerHints + (BackStackConfig to config) + val environment = newViewEnvironment + (BackStackConfig to config) val named: BackStackScreen> = newRendering // ViewStateCache requires that everything be Named. @@ -75,11 +75,11 @@ open class BackStackContainer @JvmOverloads constructor( ?.takeIf { it.canShowRendering(named.top) } ?.let { viewStateCache.prune(named.frames) - it.showRendering(named.top, hints) + it.showRendering(named.top, environment) return } - val newView = hints[ViewRegistry].buildView(named.top, hints, this) + val newView = environment[ViewRegistry].buildView(named.top, environment, this) viewStateCache.update(named.backStack, oldViewMaybe, newView) val popped = currentRendering?.backStack?.any { compatible(it, named.top) } == true diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BindingViewRegistry.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BindingViewRegistry.kt index cec3215df..042874ec5 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BindingViewRegistry.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BindingViewRegistry.kt @@ -40,7 +40,7 @@ internal class BindingViewRegistry private constructor( override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { @@ -48,7 +48,7 @@ internal class BindingViewRegistry private constructor( return (bindings[initialRendering::class] as? ViewBinding) ?.buildView( initialRendering, - initialContainerHints, + initialViewEnvironment, contextForNewView, container ) diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BuilderBinding.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BuilderBinding.kt index 2c8bb05ad..dda6fbd82 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BuilderBinding.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/BuilderBinding.kt @@ -55,15 +55,15 @@ class BuilderBinding( override val type: KClass, private val viewConstructor: ( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ) -> View ) : ViewBinding { override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? - ): View = viewConstructor(initialRendering, initialContainerHints, contextForNewView, container) + ): View = viewConstructor(initialRendering, initialViewEnvironment, contextForNewView, container) } diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/CompositeViewRegistry.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/CompositeViewRegistry.kt index 2a756495f..88d8fd954 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/CompositeViewRegistry.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/CompositeViewRegistry.kt @@ -44,7 +44,7 @@ internal class CompositeViewRegistry private constructor( override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { @@ -53,7 +53,7 @@ internal class CompositeViewRegistry private constructor( "A ${ViewBinding::class.java.name} should have been registered " + "to display $initialRendering." ) - return registry.buildView(initialRendering, initialContainerHints, contextForNewView, container) + return registry.buildView(initialRendering, initialViewEnvironment, contextForNewView, container) } companion object { diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/LayoutRunner.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/LayoutRunner.kt index a8a0c3622..0bfc1c047 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/LayoutRunner.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/LayoutRunner.kt @@ -55,7 +55,7 @@ import kotlin.reflect.KClass interface LayoutRunner { fun showRendering( rendering: RenderingT, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) class Binding( @@ -65,7 +65,7 @@ interface LayoutRunner { ) : ViewBinding { override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { @@ -75,7 +75,7 @@ interface LayoutRunner { .apply { bindShowRendering( initialRendering, - initialContainerHints, + initialViewEnvironment, runnerConstructor.invoke(this)::showRendering ) } @@ -102,7 +102,7 @@ interface LayoutRunner { object : LayoutRunner { override fun showRendering( rendering: RenderingT, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) = Unit } } diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/NamedBinding.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/NamedBinding.kt index 243ab3cf6..e5a7b7ce2 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/NamedBinding.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/NamedBinding.kt @@ -35,8 +35,8 @@ by BuilderBinding( val wrappedUpdater = view.getShowRendering()!! - view.bindShowRendering(initialRendering, initialHints) { rendering, hints -> - wrappedUpdater.invoke(rendering.wrapped, hints) + view.bindShowRendering(initialRendering, initialHints) { rendering, environment -> + wrappedUpdater.invoke(rendering.wrapped, environment) } } } diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewBinding.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewBinding.kt index d2debf513..0105da805 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewBinding.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewBinding.kt @@ -36,7 +36,7 @@ interface ViewBinding { */ fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? = null ): View diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ContainerHints.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewEnvironment.kt similarity index 55% rename from kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ContainerHints.kt rename to kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewEnvironment.kt index 248bdfec1..b86cfc7cd 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ContainerHints.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewEnvironment.kt @@ -17,41 +17,48 @@ package com.squareup.workflow.ui import kotlin.reflect.KClass +@Suppress("unused") +@Deprecated( + "Renamed to ViewEnvironment.", + replaceWith = ReplaceWith("ViewEnvironment", "com.squareup.workflow.ui.ViewEnvironment") +) +typealias ContainerHints = ViewEnvironment + /** * Immutable, append-only map of values that a parent view can pass down to * its children via [View.showRendering][android.view.View.showRendering] et al. * Allows container views to give descendants information about the context in which * they're drawing. * - * Every [ContainerHints] includes a [ViewRegistry]. This allows container views to + * Every [ViewEnvironment] includes a [ViewRegistry]. This allows container views to * make recursive [ViewRegistry.buildView] calls to build child views to show nested renderings. */ -class ContainerHints private constructor( - private val map: Map, Any> +class ViewEnvironment private constructor( + private val map: Map, Any> ) { constructor(registry: ViewRegistry) : - this(mapOf, Any>(ViewRegistry to registry)) + this(mapOf, Any>(ViewRegistry to registry)) @Suppress("UNCHECKED_CAST") - operator fun get(key: ContainerHintKey): T = map[key] as? T ?: key.default + operator fun get(key: ViewEnvironmentKey): T = map[key] as? T ?: key.default - operator fun plus(pair: Pair, T>): ContainerHints = - ContainerHints(map + pair) + operator fun plus(pair: Pair, T>): ViewEnvironment = + ViewEnvironment(map + pair) - operator fun plus(other: ContainerHints): ContainerHints = ContainerHints(map + other.map) + operator fun plus(other: ViewEnvironment): ViewEnvironment = ViewEnvironment(map + other.map) - override fun toString() = "ContainerHints($map)" + override fun toString() = "ViewEnvironment($map)" - override fun equals(other: Any?) = (other as? ContainerHints)?.let { it.map == map } ?: false + override fun equals(other: Any?) = (other as? ViewEnvironment)?.let { it.map == map } ?: false override fun hashCode() = map.hashCode() } /** - * Defines a value that can be provided by a [ContainerHints] map, specifying its [type] + * Defines a value that can be provided by a [ViewEnvironment] map, specifying its [type] * and [default] value. */ -abstract class ContainerHintKey( +abstract class ViewEnvironmentKey( private val type: KClass ) { abstract val default: T @@ -59,12 +66,12 @@ abstract class ContainerHintKey( final override fun equals(other: Any?) = when { this === other -> true other != null && this::class != other::class -> false - else -> type == (other as ContainerHintKey<*>).type + else -> type == (other as ViewEnvironmentKey<*>).type } final override fun hashCode() = type.hashCode() override fun toString(): String { - return "ContainerHintKey($type)-${super.toString()}" + return "ViewEnvironmentKey($type)-${super.toString()}" } } diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewRegistry.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewRegistry.kt index 7768a1146..e8f423d74 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewRegistry.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewRegistry.kt @@ -79,12 +79,12 @@ interface ViewRegistry { */ fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? = null ): View - companion object : ContainerHintKey(ViewRegistry::class) { + companion object : ViewEnvironmentKey(ViewRegistry::class) { override val default: ViewRegistry get() = error("There should always be a ViewRegistry hint, this is bug in Workflow.") } @@ -117,9 +117,9 @@ fun ViewRegistry(): ViewRegistry = BindingViewRegistry() */ fun ViewRegistry.buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, container: ViewGroup -): View = buildView(initialRendering, initialContainerHints, container.context, container) +): View = buildView(initialRendering, initialViewEnvironment, container.context, container) operator fun ViewRegistry.plus(binding: ViewBinding<*>): ViewRegistry = this + ViewRegistry(binding) diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewShowRendering.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewShowRendering.kt index e849cf3db..7c942859b 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewShowRendering.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/ViewShowRendering.kt @@ -21,7 +21,7 @@ import android.view.View * Function attached to a view created by [ViewRegistry], to allow it * to respond to [View.showRendering]. */ -typealias ViewShowRendering = (@UnsafeVariance RenderingT, ContainerHints) -> Unit +typealias ViewShowRendering = (@UnsafeVariance RenderingT, ViewEnvironment) -> Unit /** ` * View tag that holds the function to make the view show instances of [RenderingT], and @@ -32,7 +32,7 @@ typealias ViewShowRendering = (@UnsafeVariance RenderingT, Container */ data class ShowRenderingTag( val showing: RenderingT, - val hints: ContainerHints, + val environment: ViewEnvironment, val showRendering: ViewShowRendering ) @@ -47,14 +47,14 @@ data class ShowRenderingTag( */ fun View.bindShowRendering( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, showRendering: ViewShowRendering ) { setTag( R.id.view_show_rendering_function, - ShowRenderingTag(initialRendering, initialContainerHints, showRendering) + ShowRenderingTag(initialRendering, initialViewEnvironment, showRendering) ) - showRendering.invoke(initialRendering, initialContainerHints) + showRendering.invoke(initialRendering, initialViewEnvironment) } /** @@ -80,7 +80,7 @@ fun View.canShowRendering(rendering: Any): Boolean { */ fun View.showRendering( rendering: RenderingT, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { showRenderingTag ?.let { tag -> @@ -90,7 +90,7 @@ fun View.showRendering( "Consider using ${WorkflowViewStub::class.java.simpleName} to display arbitrary types." } - bindShowRendering(rendering, containerHints, tag.showRendering) + bindShowRendering(rendering, viewEnvironment, tag.showRendering) } ?: error( "Expected $this to have a showRendering function to show $rendering. " + @@ -114,10 +114,10 @@ fun View.getRendering(): RenderingT? { } /** - * Returns the most recent [ContainerHints] that apply to this view, or null if [bindShowRendering] + * Returns the most recent [ViewEnvironment] that apply to this view, or null if [bindShowRendering] * has never been called. */ -val View.hints: ContainerHints? get() = showRenderingTag?.hints +val View.environment: ViewEnvironment? get() = showRenderingTag?.environment /** * Returns the function set by the most recent call to [bindShowRendering], or null diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowFragment.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowFragment.kt index b521bcfa7..025873969 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowFragment.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowFragment.kt @@ -60,7 +60,7 @@ abstract class WorkflowFragment : Fragment() { /** * Provides the [ViewRegistry] used to display workflow renderings. */ - protected abstract val containerHints: ContainerHints + protected abstract val viewEnvironment: ViewEnvironment /** * Called from [onActivityCreated], so it should be safe for implementations @@ -87,6 +87,6 @@ abstract class WorkflowFragment : Fragment() { _runner = WorkflowRunner.startWorkflow(this, ::onCreateWorkflow) - (view as WorkflowLayout).start(runner.renderings, containerHints) + (view as WorkflowLayout).start(runner.renderings, viewEnvironment) } } diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowLayout.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowLayout.kt index c4b9f2f35..3b59d8526 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowLayout.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowLayout.kt @@ -52,30 +52,30 @@ class WorkflowLayout( renderings: Observable, registry: ViewRegistry ) { - start(renderings, ContainerHints(registry)) + start(renderings, ViewEnvironment(registry)) } /** - * Subscribes to [renderings], and uses the [ViewRegistry] in the given [hints] to + * Subscribes to [renderings], and uses the [ViewRegistry] in the given [environment] to * [build a new view][ViewRegistry.buildView] each time a new type of rendering is received, * making that view the only child of this one. */ fun start( renderings: Observable, - hints: ContainerHints + environment: ViewEnvironment ) { - val hintsWithDefaults = hints.withDefaultViewBindings() + val hintsWithDefaults = environment.withDefaultViewBindings() takeWhileAttached(renderings) { show(it, hintsWithDefaults) } } - private fun ContainerHints.withDefaultViewBindings(): ContainerHints = + private fun ViewEnvironment.withDefaultViewBindings(): ViewEnvironment = this + (ViewRegistry to (this[ViewRegistry] + defaultViewBindings)) private fun show( newRendering: Any, - hints: ContainerHints + environment: ViewEnvironment ) { - showing.update(newRendering, hints) + showing.update(newRendering, environment) restoredChildState?.let { restoredState -> restoredChildState = null showing.actual.restoreHierarchyState(restoredState) diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowRunner.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowRunner.kt index 3a6133897..437ede2ee 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowRunner.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowRunner.kt @@ -140,7 +140,7 @@ interface WorkflowRunner { * It creates a [WorkflowRunner] for this activity, if one doesn't already exist, and * sets a view driven by that model as the content view. * - * @param containerHints provides the [ViewRegistry] used to display workflow renderings. + * @param viewEnvironment provides the [ViewRegistry] used to display workflow renderings. * * @param configure function defining the root workflow and its environment. Called only * once per [lifecycle][FragmentActivity.getLifecycle], and always called from the UI thread. @@ -151,14 +151,14 @@ interface WorkflowRunner { * only while the activity is active, and always called from the UI thread. */ fun FragmentActivity.setContentWorkflow( - containerHints: ContainerHints, + viewEnvironment: ViewEnvironment, configure: () -> Config, onResult: (OutputT) -> Unit ): WorkflowRunner { val runner = WorkflowRunner.startWorkflow(this, configure) val layout = WorkflowLayout(this@setContentWorkflow).apply { id = R.id.workflow_layout - start(runner.renderings, containerHints) + start(runner.renderings, viewEnvironment) } runner.result.toFlowable() @@ -189,7 +189,7 @@ fun FragmentActivity.setContentWorkflow( registry: ViewRegistry, configure: () -> Config, onResult: (OutputT) -> Unit -): WorkflowRunner = setContentWorkflow(ContainerHints(registry), configure, onResult) +): WorkflowRunner = setContentWorkflow(ViewEnvironment(registry), configure, onResult) /** * For workflows that produce no output, call this method from [FragmentActivity.onCreate] @@ -197,15 +197,15 @@ fun FragmentActivity.setContentWorkflow( * It creates a [WorkflowRunner] for this activity, if one doesn't already exist, and * sets a view driven by that model as the content view. * - * @param containerHints provides the [ViewRegistry] used to display workflow renderings. + * @param viewEnvironment provides the [ViewRegistry] used to display workflow renderings. * * @param configure function defining the root workflow and its environment. Called only * once per [lifecycle][FragmentActivity.getLifecycle], and always called from the UI thread. */ fun FragmentActivity.setContentWorkflow( - containerHints: ContainerHints, + viewEnvironment: ViewEnvironment, configure: () -> Config -): WorkflowRunner = setContentWorkflow(containerHints, configure) {} +): WorkflowRunner = setContentWorkflow(viewEnvironment, configure) {} /** * For workflows that produce no output, call this method from [FragmentActivity.onCreate] @@ -221,4 +221,4 @@ fun FragmentActivity.setContentWorkflow( fun FragmentActivity.setContentWorkflow( registry: ViewRegistry, configure: () -> Config -): WorkflowRunner = setContentWorkflow(ContainerHints(registry), configure) {} +): WorkflowRunner = setContentWorkflow(ViewEnvironment(registry), configure) {} diff --git a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowViewStub.kt b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowViewStub.kt index 8418c39b2..10d810d94 100644 --- a/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowViewStub.kt +++ b/kotlin/workflow-ui/core-android/src/main/java/com/squareup/workflow/ui/WorkflowViewStub.kt @@ -83,18 +83,18 @@ class WorkflowViewStub @JvmOverloads constructor( */ fun update( rendering: Any, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ): View { actual.takeIf { it.canShowRendering(rendering) } ?.let { - it.showRendering(rendering, containerHints) + it.showRendering(rendering, viewEnvironment) return it } return when (val parent = actual.parent) { - is ViewGroup -> containerHints[ViewRegistry].buildView(rendering, containerHints, parent) + is ViewGroup -> viewEnvironment[ViewRegistry].buildView(rendering, viewEnvironment, parent) .also { buildNewViewAndReplaceOldView(parent, it) } - else -> containerHints[ViewRegistry].buildView(rendering, containerHints, actual.context) + else -> viewEnvironment[ViewRegistry].buildView(rendering, viewEnvironment, actual.context) }.also { actual = it } } diff --git a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/CompositeViewRegistryTest.kt b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/CompositeViewRegistryTest.kt index 60b9b8ad8..482919d21 100644 --- a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/CompositeViewRegistryTest.kt +++ b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/CompositeViewRegistryTest.kt @@ -106,7 +106,7 @@ class CompositeViewRegistryTest { override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View = bindings.getValue(initialRendering::class) diff --git a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/TestBinding.kt b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/TestBinding.kt index 659f9c68c..aebf96007 100644 --- a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/TestBinding.kt +++ b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/TestBinding.kt @@ -23,13 +23,13 @@ import kotlin.reflect.KClass import kotlin.test.fail fun ViewRegistry.buildView(rendering: R): View = - buildView(rendering, ContainerHints(this), mock()) + buildView(rendering, ViewEnvironment(this), mock()) class TestBinding(override val type: KClass) : ViewBinding { override fun buildView( initialRendering: R, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { diff --git a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ContainerHintsTest.kt b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ViewEnvironmentTest.kt similarity index 74% rename from kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ContainerHintsTest.kt rename to kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ViewEnvironmentTest.kt index 0b6f519ef..838638a54 100644 --- a/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ContainerHintsTest.kt +++ b/kotlin/workflow-ui/core-android/src/test/java/com/squareup/workflow/ui/ViewEnvironmentTest.kt @@ -18,12 +18,12 @@ package com.squareup.workflow.ui import com.google.common.truth.Truth.assertThat import org.junit.Test -class ContainerHintsTest { - private object StringHint : ContainerHintKey(String::class) { +class ViewEnvironmentTest { + private object StringHint : ViewEnvironmentKey(String::class) { override val default = "" } - private object OtherStringHint : ContainerHintKey(String::class) { + private object OtherStringHint : ViewEnvironmentKey(String::class) { override val default = "" } @@ -31,24 +31,24 @@ class ContainerHintsTest { val int: Int = -1, val string: String = "" ) { - companion object : ContainerHintKey(DataHint::class) { + companion object : ViewEnvironmentKey(DataHint::class) { override val default = DataHint() } } - private val emptyHints = ContainerHints(ViewRegistry()) + private val emptyHints = ViewEnvironment(ViewRegistry()) @Test fun defaults() { assertThat(emptyHints[DataHint]).isEqualTo(DataHint()) } @Test fun put() { - val hints = emptyHints + + val environment = emptyHints + (StringHint to "fnord") + (DataHint to DataHint(42, "foo")) - assertThat(hints[StringHint]).isEqualTo("fnord") - assertThat(hints[DataHint]).isEqualTo(DataHint(42, "foo")) + assertThat(environment[StringHint]).isEqualTo("fnord") + assertThat(environment[DataHint]).isEqualTo(DataHint(42, "foo")) } @Test fun `map equality`() { @@ -84,19 +84,19 @@ class ContainerHintsTest { } @Test fun override() { - val hints = emptyHints + + val environment = emptyHints + (StringHint to "able") + (StringHint to "baker") - assertThat(hints[StringHint]).isEqualTo("baker") + assertThat(environment[StringHint]).isEqualTo("baker") } @Test fun `keys of the same type`() { - val hints = emptyHints + + val environment = emptyHints + (StringHint to "able") + (OtherStringHint to "baker") - assertThat(hints[StringHint]).isEqualTo("able") - assertThat(hints[OtherStringHint]).isEqualTo("baker") + assertThat(environment[StringHint]).isEqualTo("able") + assertThat(environment[OtherStringHint]).isEqualTo("baker") } } diff --git a/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewBinding.kt b/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewBinding.kt index 9f6be354a..bd35f9c16 100644 --- a/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewBinding.kt +++ b/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewBinding.kt @@ -24,8 +24,8 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.compose.Composable import androidx.ui.core.setContent -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.bindShowRendering import kotlin.reflect.KClass @@ -54,20 +54,20 @@ import kotlin.reflect.KClass * ``` */ inline fun bindCompose( - noinline showRendering: @Composable() (RenderingT, ContainerHints) -> Unit -): ViewBinding = ComposeViewBinding(RenderingT::class) { rendering, hints -> - showRendering(rendering, hints) + noinline showRendering: @Composable() (RenderingT, ViewEnvironment) -> Unit +): ViewBinding = ComposeViewBinding(RenderingT::class) { rendering, environment -> + showRendering(rendering, environment) } @PublishedApi internal class ComposeViewBinding( override val type: KClass, - private val showRendering: @Composable() (RenderingT, ContainerHints) -> Unit + private val showRendering: @Composable() (RenderingT, ViewEnvironment) -> Unit ) : ViewBinding { override fun buildView( initialRendering: RenderingT, - initialContainerHints: ContainerHints, + initialViewEnvironment: ViewEnvironment, contextForNewView: Context, container: ViewGroup? ): View { @@ -76,10 +76,10 @@ internal class ComposeViewBinding( val composeContainer = FrameLayout(contextForNewView) composeContainer.bindShowRendering( initialRendering, - initialContainerHints - ) { rendering, hints -> + initialViewEnvironment + ) { rendering, environment -> composeContainer.setContent { - showRendering(rendering, hints) + showRendering(rendering, environment) } } return composeContainer diff --git a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/AlertContainer.kt b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/AlertContainer.kt index 0983c3972..7c0d3f5e9 100644 --- a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/AlertContainer.kt +++ b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/AlertContainer.kt @@ -24,8 +24,8 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT import androidx.annotation.StyleRes import androidx.appcompat.app.AlertDialog import com.squareup.workflow.ui.BuilderBinding -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.bindShowRendering import com.squareup.workflow.ui.modal.AlertScreen.Button import com.squareup.workflow.ui.modal.AlertScreen.Button.NEGATIVE @@ -47,11 +47,11 @@ class AlertContainer @JvmOverloads constructor( override fun buildDialog( initialModalRendering: AlertScreen, - initialContainerHints: ContainerHints + initialViewEnvironment: ViewEnvironment ): DialogRef { val dialog = AlertDialog.Builder(context, dialogThemeResId) .create() - val ref = DialogRef(initialModalRendering, initialContainerHints, dialog) + val ref = DialogRef(initialModalRendering, initialViewEnvironment, dialog) updateDialog(ref) return ref } diff --git a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalContainer.kt b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalContainer.kt index 772dd2e95..3bf9eb2ab 100644 --- a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalContainer.kt +++ b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalContainer.kt @@ -30,8 +30,8 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle.Event.ON_DESTROY import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.OnLifecycleEvent -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.Named +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.WorkflowViewStub import com.squareup.workflow.ui.compatible import com.squareup.workflow.ui.lifecycleOrNull @@ -56,17 +56,17 @@ abstract class ModalContainer @JvmOverloads constructor( protected fun update( newScreen: HasModals<*, ModalRenderingT>, - containerHints: ContainerHints + viewEnvironment: ViewEnvironment ) { - baseView.update(newScreen.beneathModals, containerHints) + baseView.update(newScreen.beneathModals, viewEnvironment) val newDialogs = mutableListOf>() for ((i, modal) in newScreen.modals.withIndex()) { newDialogs += if (i < dialogs.size && compatible(dialogs[i].modalRendering, modal)) { - dialogs[i].copy(modalRendering = modal, containerHints = containerHints) + dialogs[i].copy(modalRendering = modal, viewEnvironment = viewEnvironment) .also { updateDialog(it) } } else { - buildDialog(modal, containerHints).apply { + buildDialog(modal, viewEnvironment).apply { dialog.show() // Android makes a lot of logcat noise if it has to close the window for us. :/ // https://github.com/square/workflow/issues/51 @@ -85,7 +85,7 @@ abstract class ModalContainer @JvmOverloads constructor( */ protected abstract fun buildDialog( initialModalRendering: ModalRenderingT, - initialContainerHints: ContainerHints + initialViewEnvironment: ViewEnvironment ): DialogRef protected abstract fun updateDialog(dialogRef: DialogRef) @@ -139,7 +139,7 @@ abstract class ModalContainer @JvmOverloads constructor( */ protected data class DialogRef( val modalRendering: ModalRenderingT, - val containerHints: ContainerHints, + val viewEnvironment: ViewEnvironment, val dialog: Dialog, val extra: Any? = null ) { diff --git a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalViewContainer.kt b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalViewContainer.kt index a7d22d496..2d1cea3b5 100644 --- a/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalViewContainer.kt +++ b/kotlin/workflow-ui/modal-android/src/main/java/com/squareup/workflow/ui/modal/ModalViewContainer.kt @@ -26,8 +26,8 @@ import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.annotation.IdRes import com.squareup.workflow.ui.BuilderBinding -import com.squareup.workflow.ui.ContainerHints import com.squareup.workflow.ui.ViewBinding +import com.squareup.workflow.ui.ViewEnvironment import com.squareup.workflow.ui.ViewRegistry import com.squareup.workflow.ui.backPressedHandler import com.squareup.workflow.ui.bindShowRendering @@ -73,10 +73,10 @@ open class ModalViewContainer @JvmOverloads constructor( final override fun buildDialog( initialModalRendering: Any, - initialContainerHints: ContainerHints + initialViewEnvironment: ViewEnvironment ): DialogRef { - val view = initialContainerHints[ViewRegistry] - .buildView(initialModalRendering, initialContainerHints, this) + val view = initialViewEnvironment[ViewRegistry] + .buildView(initialModalRendering, initialViewEnvironment, this) .apply { // If the modal's root view has no backPressedHandler, add a no-op one to // ensure that the `onBackPressed` call below will not leak up to handlers @@ -108,12 +108,12 @@ open class ModalViewContainer @JvmOverloads constructor( } } .run { - DialogRef(initialModalRendering, initialContainerHints, this, view) + DialogRef(initialModalRendering, initialViewEnvironment, this, view) } } override fun updateDialog(dialogRef: DialogRef) { - with(dialogRef) { (extra as View).showRendering(modalRendering, containerHints) } + with(dialogRef) { (extra as View).showRendering(modalRendering, viewEnvironment) } } @PublishedApi