Skip to content

Commit

Permalink
Merge pull request #1118 from square/ray/really-it-is-deprecated-for-…
Browse files Browse the repository at this point in the history
…real

Forgot to re-deprecate a couple of pre-Overlay things.
  • Loading branch information
rjrjr authored Oct 13, 2023
2 parents 0a14ba0 + 9b44a6a commit ad05052
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("DEPRECATION")
@file:OptIn(WorkflowExperimentalRuntime::class)

package com.squareup.sample.compose.hellocomposebinding
Expand All @@ -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
Expand All @@ -39,20 +41,19 @@ class HelloBindingActivity : AppCompatActivity() {
val model: HelloBindingModel by viewModels()
setContentView(
WorkflowLayout(this).apply {
start(
take(
lifecycle = lifecycle,
renderings = model.renderings,
environment = viewEnvironment
)
}
)
}

class HelloBindingModel(savedState: SavedStateHandle) : ViewModel() {
@OptIn(WorkflowUiExperimentalApi::class)
val renderings: StateFlow<Any> by lazy {
val renderings: StateFlow<Screen> by lazy {
renderWorkflowIn(
workflow = HelloWorkflow,
workflow = HelloWorkflow.mapRendering { it.withEnvironment(viewEnvironment) },
scope = viewModelScope,
savedStateHandle = savedState,
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("DEPRECATION")
@file:OptIn(WorkflowExperimentalRuntime::class)

package com.squareup.sample.compose.hellocomposeworkflow
Expand All @@ -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
Expand All @@ -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<Any> by lazy {
val renderings: StateFlow<Screen> by lazy {
renderWorkflowIn(
workflow = HelloWorkflow,
scope = viewModelScope,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("DEPRECATION")
@file:OptIn(WorkflowExperimentalRuntime::class)

package com.squareup.sample.compose.inlinerendering
Expand All @@ -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
Expand All @@ -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<Any> by lazy {
val renderings: StateFlow<Screen> by lazy {
renderWorkflowIn(
workflow = InlineRenderingWorkflow,
scope = viewModelScope,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.squareup.sample.compose.nestedrenderings

import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -25,7 +23,7 @@ class LegacyRunner(private val binding: LegacyViewBinding) : ScreenViewRunner<Le
rendering: LegacyRendering,
environment: ViewEnvironment
) {
binding.stub.update(rendering.rendering, environment)
binding.stub.show(rendering.rendering, environment)
}

companion object : ScreenViewFactory<LegacyRendering> by fromViewBinding(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("DEPRECATION")
@file:OptIn(WorkflowExperimentalRuntime::class)

package com.squareup.sample.compose.nestedrenderings
Expand All @@ -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
Expand All @@ -44,20 +46,19 @@ class NestedRenderingsActivity : AppCompatActivity() {
val model: NestedRenderingsModel by viewModels()
setContentView(
WorkflowLayout(this).apply {
start(
take(
lifecycle = lifecycle,
renderings = model.renderings,
environment = viewEnvironment
)
}
)
}

class NestedRenderingsModel(savedState: SavedStateHandle) : ViewModel() {
@OptIn(WorkflowUiExperimentalApi::class)
val renderings: StateFlow<Any> by lazy {
val renderings: StateFlow<Screen> by lazy {
renderWorkflowIn(
workflow = RecursiveWorkflow,
workflow = RecursiveWorkflow.mapRendering { it.withEnvironment(viewEnvironment) },
scope = viewModelScope,
savedStateHandle = savedState,
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("DEPRECATION")
@file:OptIn(WorkflowUiExperimentalApi::class, WorkflowExperimentalRuntime::class)

package com.squareup.sample.hellobackbutton
Expand All @@ -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?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.squareup.sample.dungeon

import android.content.Context.VIBRATOR_SERVICE
Expand All @@ -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
Expand All @@ -31,7 +28,6 @@ class Component(context: AppCompatActivity) {
LoadingScreenViewFactory<Loading>(R.string.loading_board),
GameLayoutRunner,
BoardView,
AlertContainer
)

val random = Random(System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.squareup.sample.dungeon

import com.squareup.sample.dungeon.DungeonAppWorkflow.Props
Expand All @@ -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<Props, State, Nothing, AlertContainerScreen<Any>>() {
) : StatefulWorkflow<Props, State, Nothing, BodyAndOverlaysScreen<Screen, Overlay>>() {

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<Pair<String, Board>>) : State()
data class PlayingGame(val boardPath: BoardPath) : State()
}
Expand All @@ -45,18 +44,18 @@ class DungeonAppWorkflow(
renderProps: Props,
renderState: State,
context: RenderContext
): AlertContainerScreen<Any> = when (renderState) {
): BodyAndOverlaysScreen<Screen, Overlay> = when (renderState) {
LoadingBoardList -> {
context.runningWorker(boardLoader.loadAvailableBoards()) { displayBoards(it) }
AlertContainerScreen(renderState)
BodyAndOverlaysScreen(renderState)
}

is ChoosingBoard -> {
val screen = DisplayBoardsListScreen(
boards = renderState.boards.map { it.second },
onBoardSelected = { index -> context.actionSink.send(selectBoard(index)) }
)
AlertContainerScreen(screen)
BodyAndOverlaysScreen(screen)
}

is PlayingGame -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.squareup.sample.dungeon

import android.os.Vibrator
Expand All @@ -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

Expand All @@ -33,7 +32,7 @@ class GameSessionWorkflow(
private val gameWorkflow: GameWorkflow,
private val vibrator: Vibrator,
private val boardLoader: BoardLoader
) : StatefulWorkflow<Props, State, Nothing, AlertContainerScreen<Any>>() {
) : StatefulWorkflow<Props, State, Nothing, BodyAndOverlaysScreen<Screen, Overlay>>() {

data class Props(
val boardPath: BoardPath,
Expand All @@ -55,32 +54,32 @@ class GameSessionWorkflow(
renderProps: Props,
renderState: State,
context: RenderContext
): AlertContainerScreen<Any> = when (renderState) {
): BodyAndOverlaysScreen<Screen, Overlay> = when (renderState) {
Loading -> {
context.runningWorker(boardLoader.loadBoard(renderProps.boardPath)) { StartRunning(it) }
AlertContainerScreen(Loading)
BodyAndOverlaysScreen(Loading)
}

is Running -> {
val gameInput = GameWorkflow.Props(renderState.board, paused = renderProps.paused)
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))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("DEPRECATION")

package com.squareup.sample.mainactivity

import android.os.Bundle
Expand All @@ -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
Expand Down Expand Up @@ -51,7 +47,6 @@ class TicTacToeActivity : AppCompatActivity() {
private companion object {
val viewRegistry = SampleContainers +
AuthViewFactories +
TicTacToeViewFactories +
AlertContainer
TicTacToeViewFactories
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package com.squareup.workflow1.ui.modal.test

import android.view.View
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @file:Suppress("DEPRECATION")

package com.squareup.workflow1.ui.modal

import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
Expand All @@ -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<B>(beneathModals, modals)",
// "com.squareup.workflow1.ui.container.BodyAndModalsScreen"
// )
// )
@Deprecated(
"Use BodyAndModalsScreen and AlertOverlay",
ReplaceWith(
"BodyAndModalsScreen<B>(beneathModals, modals)",
"com.squareup.workflow1.ui.container.BodyAndModalsScreen"
)
)
public data class AlertContainerScreen<B : Any>(
override val beneathModals: B,
override val modals: List<AlertScreen> = emptyList()
Expand Down
Loading

0 comments on commit ad05052

Please sign in to comment.