diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt index aedfc43e9..872ac7de0 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt @@ -1,4 +1,3 @@ -@file:Suppress("DEPRECATION") @file:OptIn(WorkflowExperimentalRuntime::class) package com.squareup.sample.compose.hellocomposebinding @@ -12,12 +11,15 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.squareup.workflow1.WorkflowExperimentalRuntime import com.squareup.workflow1.config.AndroidRuntimeConfigTools +import com.squareup.workflow1.mapRendering +import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.ViewEnvironment import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.compose.composeViewFactory import com.squareup.workflow1.ui.compose.withCompositionRoot +import com.squareup.workflow1.ui.container.withEnvironment import com.squareup.workflow1.ui.plus import com.squareup.workflow1.ui.renderWorkflowIn import kotlinx.coroutines.flow.StateFlow @@ -39,10 +41,9 @@ class HelloBindingActivity : AppCompatActivity() { val model: HelloBindingModel by viewModels() setContentView( WorkflowLayout(this).apply { - start( + take( lifecycle = lifecycle, renderings = model.renderings, - environment = viewEnvironment ) } ) @@ -50,9 +51,9 @@ class HelloBindingActivity : AppCompatActivity() { class HelloBindingModel(savedState: SavedStateHandle) : ViewModel() { @OptIn(WorkflowUiExperimentalApi::class) - val renderings: StateFlow by lazy { + val renderings: StateFlow by lazy { renderWorkflowIn( - workflow = HelloWorkflow, + workflow = HelloWorkflow.mapRendering { it.withEnvironment(viewEnvironment) }, scope = viewModelScope, savedStateHandle = savedState, runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig() diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowActivity.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowActivity.kt index 9d12b12e6..8526eb7b6 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowActivity.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowActivity.kt @@ -1,4 +1,3 @@ -@file:Suppress("DEPRECATION") @file:OptIn(WorkflowExperimentalRuntime::class) package com.squareup.sample.compose.hellocomposeworkflow @@ -11,6 +10,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.squareup.workflow1.WorkflowExperimentalRuntime import com.squareup.workflow1.config.AndroidRuntimeConfigTools +import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.renderWorkflowIn @@ -22,13 +22,13 @@ class HelloComposeWorkflowActivity : AppCompatActivity() { super.onCreate(savedInstanceState) val model: HelloComposeModel by viewModels() setContentView( - WorkflowLayout(this).apply { start(lifecycle, model.renderings) } + WorkflowLayout(this).apply { take(lifecycle, model.renderings) } ) } class HelloComposeModel(savedState: SavedStateHandle) : ViewModel() { @OptIn(WorkflowUiExperimentalApi::class) - val renderings: StateFlow by lazy { + val renderings: StateFlow by lazy { renderWorkflowIn( workflow = HelloWorkflow, scope = viewModelScope, diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingActivity.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingActivity.kt index c4c541a88..b6f50e7dc 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingActivity.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingActivity.kt @@ -1,4 +1,3 @@ -@file:Suppress("DEPRECATION") @file:OptIn(WorkflowExperimentalRuntime::class) package com.squareup.sample.compose.inlinerendering @@ -11,6 +10,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.squareup.workflow1.WorkflowExperimentalRuntime import com.squareup.workflow1.config.AndroidRuntimeConfigTools +import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.renderWorkflowIn @@ -26,13 +26,13 @@ class InlineRenderingActivity : AppCompatActivity() { val model: HelloBindingModel by viewModels() setContentView( - WorkflowLayout(this).apply { start(lifecycle, model.renderings) } + WorkflowLayout(this).apply { take(lifecycle, model.renderings) } ) } class HelloBindingModel(savedState: SavedStateHandle) : ViewModel() { @OptIn(WorkflowUiExperimentalApi::class) - val renderings: StateFlow by lazy { + val renderings: StateFlow by lazy { renderWorkflowIn( workflow = InlineRenderingWorkflow, scope = viewModelScope, diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/LegacyRunner.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/LegacyRunner.kt index 485d8b0f7..e9296e3dd 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/LegacyRunner.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/LegacyRunner.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.squareup.sample.compose.nestedrenderings import androidx.compose.foundation.layout.fillMaxSize @@ -25,7 +23,7 @@ class LegacyRunner(private val binding: LegacyViewBinding) : ScreenViewRunner by fromViewBinding( diff --git a/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt b/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt index 3e6b11505..72b69310b 100644 --- a/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt +++ b/samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt @@ -1,4 +1,3 @@ -@file:Suppress("DEPRECATION") @file:OptIn(WorkflowExperimentalRuntime::class) package com.squareup.sample.compose.nestedrenderings @@ -13,11 +12,14 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.squareup.workflow1.WorkflowExperimentalRuntime import com.squareup.workflow1.config.AndroidRuntimeConfigTools +import com.squareup.workflow1.mapRendering +import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.ViewEnvironment import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.compose.withCompositionRoot +import com.squareup.workflow1.ui.container.withEnvironment import com.squareup.workflow1.ui.plus import com.squareup.workflow1.ui.renderWorkflowIn import kotlinx.coroutines.flow.StateFlow @@ -44,10 +46,9 @@ class NestedRenderingsActivity : AppCompatActivity() { val model: NestedRenderingsModel by viewModels() setContentView( WorkflowLayout(this).apply { - start( + take( lifecycle = lifecycle, renderings = model.renderings, - environment = viewEnvironment ) } ) @@ -55,9 +56,9 @@ class NestedRenderingsActivity : AppCompatActivity() { class NestedRenderingsModel(savedState: SavedStateHandle) : ViewModel() { @OptIn(WorkflowUiExperimentalApi::class) - val renderings: StateFlow by lazy { + val renderings: StateFlow by lazy { renderWorkflowIn( - workflow = RecursiveWorkflow, + workflow = RecursiveWorkflow.mapRendering { it.withEnvironment(viewEnvironment) }, scope = viewModelScope, savedStateHandle = savedState, runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig() diff --git a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonActivity.kt b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonActivity.kt index 630cbc181..09f201722 100644 --- a/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonActivity.kt +++ b/samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonActivity.kt @@ -1,4 +1,3 @@ -@file:Suppress("DEPRECATION") @file:OptIn(WorkflowUiExperimentalApi::class, WorkflowExperimentalRuntime::class) package com.squareup.sample.hellobackbutton @@ -17,15 +16,13 @@ import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.container.withRegistry -import com.squareup.workflow1.ui.modal.AlertContainer -import com.squareup.workflow1.ui.plus import com.squareup.workflow1.ui.renderWorkflowIn import kotlinx.coroutines.Job import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch -private val viewRegistry = SampleContainers + AlertContainer +private val viewRegistry = SampleContainers class HelloBackButtonActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/Component.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/Component.kt index 43f6fd4a0..c4a925b11 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/Component.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/Component.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.squareup.sample.dungeon import android.content.Context.VIBRATOR_SERVICE @@ -10,7 +8,6 @@ import com.squareup.sample.dungeon.GameSessionWorkflow.State.Loading import com.squareup.sample.timemachine.shakeable.ShakeableTimeMachineLayoutRunner import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.modal.AlertContainer import kotlinx.coroutines.Dispatchers import kotlin.random.Random import kotlin.time.ExperimentalTime @@ -31,7 +28,6 @@ class Component(context: AppCompatActivity) { LoadingScreenViewFactory(R.string.loading_board), GameLayoutRunner, BoardView, - AlertContainer ) val random = Random(System.currentTimeMillis()) diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt index 80bb993c2..ce4500087 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/DungeonAppWorkflow.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.squareup.sample.dungeon import com.squareup.sample.dungeon.DungeonAppWorkflow.Props @@ -15,18 +13,19 @@ import com.squareup.workflow1.renderChild import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.modal.AlertContainerScreen +import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen +import com.squareup.workflow1.ui.container.Overlay @OptIn(WorkflowUiExperimentalApi::class) class DungeonAppWorkflow( private val gameSessionWorkflow: GameSessionWorkflow, private val boardLoader: BoardLoader -) : StatefulWorkflow>() { +) : StatefulWorkflow>() { data class Props(val paused: Boolean = false) - sealed class State { - object LoadingBoardList : State(), Screen + sealed class State : Screen { + object LoadingBoardList : State() data class ChoosingBoard(val boards: List>) : State() data class PlayingGame(val boardPath: BoardPath) : State() } @@ -45,10 +44,10 @@ class DungeonAppWorkflow( renderProps: Props, renderState: State, context: RenderContext - ): AlertContainerScreen = when (renderState) { + ): BodyAndOverlaysScreen = when (renderState) { LoadingBoardList -> { context.runningWorker(boardLoader.loadAvailableBoards()) { displayBoards(it) } - AlertContainerScreen(renderState) + BodyAndOverlaysScreen(renderState) } is ChoosingBoard -> { @@ -56,7 +55,7 @@ class DungeonAppWorkflow( boards = renderState.boards.map { it.second }, onBoardSelected = { index -> context.actionSink.send(selectBoard(index)) } ) - AlertContainerScreen(screen) + BodyAndOverlaysScreen(screen) } is PlayingGame -> { diff --git a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt index 270b964d7..f9eb56036 100644 --- a/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt +++ b/samples/dungeon/app/src/main/java/com/squareup/sample/dungeon/GameSessionWorkflow.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.squareup.sample.dungeon import android.os.Vibrator @@ -19,9 +17,10 @@ import com.squareup.workflow1.action import com.squareup.workflow1.runningWorker import com.squareup.workflow1.ui.Screen import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.modal.AlertContainerScreen -import com.squareup.workflow1.ui.modal.AlertScreen -import com.squareup.workflow1.ui.modal.AlertScreen.Button.POSITIVE +import com.squareup.workflow1.ui.container.AlertOverlay +import com.squareup.workflow1.ui.container.AlertOverlay.Button.POSITIVE +import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen +import com.squareup.workflow1.ui.container.Overlay typealias BoardPath = String @@ -33,7 +32,7 @@ class GameSessionWorkflow( private val gameWorkflow: GameWorkflow, private val vibrator: Vibrator, private val boardLoader: BoardLoader -) : StatefulWorkflow>() { +) : StatefulWorkflow>() { data class Props( val boardPath: BoardPath, @@ -55,10 +54,10 @@ class GameSessionWorkflow( renderProps: Props, renderState: State, context: RenderContext - ): AlertContainerScreen = when (renderState) { + ): BodyAndOverlaysScreen = when (renderState) { Loading -> { context.runningWorker(boardLoader.loadBoard(renderProps.boardPath)) { StartRunning(it) } - AlertContainerScreen(Loading) + BodyAndOverlaysScreen(Loading) } is Running -> { @@ -66,21 +65,21 @@ class GameSessionWorkflow( val gameScreen = context.renderChild(gameWorkflow, gameInput) { handleGameOutput(it, renderState.board) } - AlertContainerScreen(gameScreen) + BodyAndOverlaysScreen(gameScreen) } is GameOver -> { val gameInput = GameWorkflow.Props(renderState.board) val gameScreen = context.renderChild(gameWorkflow, gameInput) { noAction() } - val gameOverDialog = AlertScreen( + val gameOverDialog = AlertOverlay( buttons = mapOf(POSITIVE to "Restart"), message = "You've been eaten, try again.", cancelable = false, onEvent = { context.actionSink.send(restartGame()) } ) - AlertContainerScreen(gameScreen, gameOverDialog) + BodyAndOverlaysScreen(gameScreen, listOf(gameOverDialog)) } } diff --git a/samples/tictactoe/app/src/main/java/com/squareup/sample/mainactivity/TicTacToeActivity.kt b/samples/tictactoe/app/src/main/java/com/squareup/sample/mainactivity/TicTacToeActivity.kt index 9f37bac85..768be6287 100644 --- a/samples/tictactoe/app/src/main/java/com/squareup/sample/mainactivity/TicTacToeActivity.kt +++ b/samples/tictactoe/app/src/main/java/com/squareup/sample/mainactivity/TicTacToeActivity.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.squareup.sample.mainactivity import android.os.Bundle @@ -13,9 +11,7 @@ import com.squareup.sample.gameworkflow.TicTacToeViewFactories import com.squareup.workflow1.ui.WorkflowLayout import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.container.withRegistry -import com.squareup.workflow1.ui.modal.AlertContainer import com.squareup.workflow1.ui.plus -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import timber.log.Timber @@ -51,7 +47,6 @@ class TicTacToeActivity : AppCompatActivity() { private companion object { val viewRegistry = SampleContainers + AuthViewFactories + - TicTacToeViewFactories + - AlertContainer + TicTacToeViewFactories } } diff --git a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleActivity.kt b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleActivity.kt index 27dbe0397..6e798699a 100644 --- a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleActivity.kt +++ b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleActivity.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package com.squareup.workflow1.ui.modal.test import android.view.View diff --git a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertContainerScreen.kt b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertContainerScreen.kt index ed26c0017..d68ade722 100644 --- a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertContainerScreen.kt +++ b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertContainerScreen.kt @@ -1,5 +1,3 @@ -// @file:Suppress("DEPRECATION") - package com.squareup.workflow1.ui.modal import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -14,14 +12,15 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi * * @param B the type of [beneathModals] */ +@Suppress("DEPRECATION") @WorkflowUiExperimentalApi -// @Deprecated( -// "Use BodyAndModalsScreen and AlertOverlay", -// ReplaceWith( -// "BodyAndModalsScreen(beneathModals, modals)", -// "com.squareup.workflow1.ui.container.BodyAndModalsScreen" -// ) -// ) +@Deprecated( + "Use BodyAndModalsScreen and AlertOverlay", + ReplaceWith( + "BodyAndModalsScreen(beneathModals, modals)", + "com.squareup.workflow1.ui.container.BodyAndModalsScreen" + ) +) public data class AlertContainerScreen( override val beneathModals: B, override val modals: List = emptyList() diff --git a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertScreen.kt b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertScreen.kt index f1fb7f957..8b99a5196 100644 --- a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertScreen.kt +++ b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/AlertScreen.kt @@ -1,5 +1,3 @@ -// @file:Suppress("DEPRECATION") - package com.squareup.workflow1.ui.modal import com.squareup.workflow1.ui.WorkflowUiExperimentalApi @@ -11,13 +9,13 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi * Models a typical "You sure about that?" alert box. */ @WorkflowUiExperimentalApi -// @Deprecated( -// "Use AlertOverlay", -// ReplaceWith( -// "AlertOverlay(buttons, message, title, cancelable, onEvent)", -// "com.squareup.workflow1.ui.container.AlertOverlay" -// ) -// ) +@Deprecated( + "Use AlertOverlay", + ReplaceWith( + "AlertOverlay(buttons, message, title, cancelable, onEvent)", + "com.squareup.workflow1.ui.container.AlertOverlay" + ) +) public data class AlertScreen( val buttons: Map = emptyMap(), val message: String = "", @@ -41,6 +39,7 @@ public data class AlertScreen( if (this === other) return true if (javaClass != other?.javaClass) return false + @Suppress("DEPRECATION") other as AlertScreen return buttons == other.buttons && diff --git a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/HasModals.kt b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/HasModals.kt index 4bf4deae8..65d46a344 100644 --- a/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/HasModals.kt +++ b/workflow-ui/container-common/src/main/java/com/squareup/workflow1/ui/modal/HasModals.kt @@ -14,7 +14,7 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi * like `ModalContainer` in the `workflow-ui:core-android` module. */ @WorkflowUiExperimentalApi -// @Deprecated("Use BodyAndModalsScreen") +@Deprecated("Use BodyAndModalsScreen") public interface HasModals { public val beneathModals: B public val modals: List