Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package com.squareup.benchmarks.performance.complex.poetry.views
import com.squareup.sample.container.overviewdetail.OverviewDetailScreen
import com.squareup.sample.container.panel.ScrimScreen
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.BodyAndModalsScreen
import com.squareup.workflow1.ui.container.ModalScreenOverlay
import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen
import com.squareup.workflow1.ui.container.FullScreenOverlay

@OptIn(WorkflowUiExperimentalApi::class)
typealias MayBeLoadingScreen =
BodyAndModalsScreen<ScrimScreen<OverviewDetailScreen>, ModalScreenOverlay<LoaderSpinner>>
BodyAndOverlaysScreen<ScrimScreen<OverviewDetailScreen>, FullScreenOverlay<LoaderSpinner>>

@OptIn(WorkflowUiExperimentalApi::class)
fun MayBeLoadingScreen(
baseScreen: OverviewDetailScreen,
loaders: List<LoaderSpinner> = emptyList()
): MayBeLoadingScreen {
return BodyAndModalsScreen(
return BodyAndOverlaysScreen(
ScrimScreen(baseScreen, dimmed = loaders.isNotEmpty()),
loaders.map { ModalScreenOverlay(it) }
loaders.map { FullScreenOverlay(it) }
)
}

Expand All @@ -27,4 +27,4 @@ val MayBeLoadingScreen.baseScreen: OverviewDetailScreen

@OptIn(WorkflowUiExperimentalApi::class)
val MayBeLoadingScreen.loaders: List<LoaderSpinner>
get() = modals.map { it.content }
get() = overlays.map { it.content }
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import android.graphics.Rect
import android.view.View
import com.squareup.sample.container.R
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.ModalScreenOverlayDialogFactory
import com.squareup.workflow1.ui.container.ScreenOverlayDialogFactory
import com.squareup.workflow1.ui.container.setModalContent

/**
* Android support for [PanelOverlay].
*/
@OptIn(WorkflowUiExperimentalApi::class)
internal object PanelOverlayDialogFactory : ModalScreenOverlayDialogFactory<PanelOverlay<*>>(
internal object PanelOverlayDialogFactory : ScreenOverlayDialogFactory<PanelOverlay<*>>(
type = PanelOverlay::class
) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.squareup.sample.container.panel

import com.squareup.workflow1.ui.Screen
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.ModalOverlay
import com.squareup.workflow1.ui.container.ScreenOverlay

@OptIn(WorkflowUiExperimentalApi::class)
class PanelOverlay<T : Screen>(
override val content: T
) : ScreenOverlay<T>
) : ScreenOverlay<T>, ModalOverlay
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.squareup.workflow1.ui.container.AlertOverlay.Button.POSITIVE
import com.squareup.workflow1.ui.container.AlertOverlay.Event.ButtonClicked
import com.squareup.workflow1.ui.container.AlertOverlay.Event.Canceled
import com.squareup.workflow1.ui.container.BackButtonScreen
import com.squareup.workflow1.ui.container.BodyAndModalsScreen
import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen
import com.squareup.workflow1.ui.toParcelable
import com.squareup.workflow1.ui.toSnapshot
import kotlinx.parcelize.Parcelize
Expand All @@ -27,7 +27,7 @@ import kotlinx.parcelize.Parcelize
*/
@OptIn(WorkflowUiExperimentalApi::class)
object AreYouSureWorkflow :
StatefulWorkflow<Unit, State, Finished, BodyAndModalsScreen<*, AlertOverlay>>() {
StatefulWorkflow<Unit, State, Finished, BodyAndOverlaysScreen<*, AlertOverlay>>() {
override fun initialState(
props: Unit,
snapshot: Snapshot?
Expand All @@ -45,12 +45,12 @@ object AreYouSureWorkflow :
renderProps: Unit,
renderState: State,
context: RenderContext
): BodyAndModalsScreen<*, AlertOverlay> {
): BodyAndOverlaysScreen<*, AlertOverlay> {
val ableBakerCharlie = context.renderChild(HelloBackButtonWorkflow, Unit) { noAction() }

return when (renderState) {
Running -> {
BodyAndModalsScreen(
BodyAndOverlaysScreen(
BackButtonScreen(ableBakerCharlie) {
// While we always provide a back button handler, by default the view code
// associated with BackButtonScreen ignores ours if the view created for the
Expand Down Expand Up @@ -80,7 +80,7 @@ object AreYouSureWorkflow :
}
)

BodyAndModalsScreen(ableBakerCharlie, alert)
BodyAndOverlaysScreen(ableBakerCharlie, alert)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.squareup.workflow1.action
import com.squareup.workflow1.renderChild
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.BackStackScreen
import com.squareup.workflow1.ui.container.BodyAndModalsScreen
import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen

/**
* Application specific root [Workflow], and demonstration of workflow composition.
Expand All @@ -45,7 +45,7 @@ import com.squareup.workflow1.ui.container.BodyAndModalsScreen
class TicTacToeWorkflow(
private val authWorkflow: AuthWorkflow,
private val runGameWorkflow: RunGameWorkflow
) : StatefulWorkflow<Unit, MainState, Unit, BodyAndModalsScreen<ScrimScreen<*>, *>>() {
) : StatefulWorkflow<Unit, MainState, Unit, BodyAndOverlaysScreen<ScrimScreen<*>, *>>() {

override fun initialState(
props: Unit,
Expand All @@ -57,8 +57,8 @@ class TicTacToeWorkflow(
renderProps: Unit,
renderState: MainState,
context: RenderContext
): BodyAndModalsScreen<ScrimScreen<*>, *> {
val bodyAndModals: BodyAndModalsScreen<*, *> = when (renderState) {
): BodyAndOverlaysScreen<ScrimScreen<*>, *> {
val bodyAndOverlays: BodyAndOverlaysScreen<*, *> = when (renderState) {
is Authenticating -> {
val authBackStack = context.renderChild(authWorkflow) { handleAuthResult(it) }
// We always show an empty GameScreen behind the PanelOverlay that
Expand All @@ -68,14 +68,14 @@ class TicTacToeWorkflow(
// cheat is probably the most realistic thing about this sample.
val emptyGameScreen = GamePlayScreen()

BodyAndModalsScreen(emptyGameScreen, PanelOverlay(authBackStack))
BodyAndOverlaysScreen(emptyGameScreen, PanelOverlay(authBackStack))
}

is RunningGame -> {
val gameRendering = context.renderChild(runGameWorkflow) { startAuth }

if (gameRendering.namePrompt == null) {
BodyAndModalsScreen(gameRendering.gameScreen, gameRendering.alerts)
BodyAndOverlaysScreen(gameRendering.gameScreen, gameRendering.alerts)
} else {
// To prompt for player names, the child puts up a ScreenOverlay, which
// we replace here with a tasteful PanelOverlay.
Expand All @@ -95,14 +95,14 @@ class TicTacToeWorkflow(
BackStackScreen(gameRendering.namePrompt.content)
val allModals = listOf(PanelOverlay(fullBackStack)) + gameRendering.alerts

BodyAndModalsScreen(gameRendering.gameScreen, allModals)
BodyAndOverlaysScreen(gameRendering.gameScreen, allModals)
}
}
}

// Add the scrim. Dim it only if there is a panel showing.
val dim = bodyAndModals.modals.any { modal -> modal is PanelOverlay<*> }
return bodyAndModals.mapBody { body -> ScrimScreen(body, dimmed = dim) }
val dim = bodyAndOverlays.overlays.any { modal -> modal is PanelOverlay<*> }
return bodyAndOverlays.mapBody { body -> ScrimScreen(body, dimmed = dim) }
}

override fun snapshotState(state: MainState): Snapshot = state.toSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.squareup.workflow1.testing.launchForTestingFromStartWith
import com.squareup.workflow1.ui.Screen
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.BackStackScreen
import com.squareup.workflow1.ui.container.BodyAndModalsScreen
import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen
import org.junit.Test

/**
Expand Down Expand Up @@ -63,8 +63,8 @@ class TicTacToeWorkflowTest {
private fun authScreen(wrapped: String = DEFAULT_AUTH) =
BackStackScreen<Screen>(S(wrapped))

private val BodyAndModalsScreen<ScrimScreen<*>, *>.panels: List<PanelOverlay<*>>
get() = modals.mapNotNull { it as? PanelOverlay<*> }
private val BodyAndOverlaysScreen<ScrimScreen<*>, *>.panels: List<PanelOverlay<*>>
get() = overlays.mapNotNull { it as? PanelOverlay<*> }

private fun authWorkflow(
screen: String = DEFAULT_AUTH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import com.squareup.workflow1.ui.ViewRegistry
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.container.AndroidOverlay
import com.squareup.workflow1.ui.container.BackStackScreen
import com.squareup.workflow1.ui.container.BodyAndModalsScreen
import com.squareup.workflow1.ui.container.ModalScreenOverlayDialogFactory
import com.squareup.workflow1.ui.container.BodyAndOverlaysScreen
import com.squareup.workflow1.ui.container.ScreenOverlay
import com.squareup.workflow1.ui.container.ScreenOverlayDialogFactory
import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
Expand Down Expand Up @@ -371,7 +371,7 @@ internal class ComposeViewTreeIntegrationTest {
// Show first screen to initialize state.
scenario.onActivity {
it.setRendering(
BodyAndModalsScreen(
BodyAndOverlaysScreen(
EmptyRendering, TestModal(BackStackScreen(EmptyRendering, firstScreen))
)
)
Expand Down Expand Up @@ -426,7 +426,7 @@ internal class ComposeViewTreeIntegrationTest {
// Show first screen to initialize state.
scenario.onActivity {
it.setRendering(
BodyAndModalsScreen(
BodyAndOverlaysScreen(
EmptyRendering, TestModal(firstScreen), TestModal(secondScreen), TestModal(thirdScreen)
)
)
Expand Down Expand Up @@ -485,7 +485,7 @@ internal class ComposeViewTreeIntegrationTest {
// Show first screen to initialize state.
scenario.onActivity {
it.setRendering(
BodyAndModalsScreen(
BodyAndOverlaysScreen(
EmptyRendering,
TestModal(BackStackScreen(EmptyRendering, layer0Screen0)),
TestModal(BackStackScreen(EmptyRendering, layer1Screen0)),
Expand All @@ -508,7 +508,7 @@ internal class ComposeViewTreeIntegrationTest {
// Push some screens onto the backstack.
scenario.onActivity {
it.setRendering(
BodyAndModalsScreen(
BodyAndOverlaysScreen(
EmptyRendering,
TestModal(BackStackScreen(EmptyRendering, layer0Screen0, layer0Screen1)),
TestModal(BackStackScreen(EmptyRendering, layer1Screen0, layer1Screen1)),
Expand Down Expand Up @@ -545,7 +545,7 @@ internal class ComposeViewTreeIntegrationTest {
// Pop both backstacks and check that screens were restored.
scenario.onActivity {
it.setRendering(
BodyAndModalsScreen(
BodyAndOverlaysScreen(
EmptyRendering,
TestModal(BackStackScreen(EmptyRendering, layer0Screen0)),
TestModal(BackStackScreen(EmptyRendering, layer1Screen0)),
Expand All @@ -566,7 +566,7 @@ internal class ComposeViewTreeIntegrationTest {
data class TestModal(
override val content: Screen
) : ScreenOverlay<Screen>, AndroidOverlay<TestModal> {
override val dialogFactory = object : ModalScreenOverlayDialogFactory<TestModal>(
override val dialogFactory = object : ScreenOverlayDialogFactory<TestModal>(
TestModal::class
) {
override fun buildDialogWithContentView(contentView: View): Dialog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
/**
* **This will be deprecated in favor of
* [AlertOverlay][com.squareup.workflow1.ui.container.AlertOverlay] and
* [BodyAndModalsScreen][com.squareup.workflow1.ui.container.BodyAndModalsScreen]
* [BodyAndModalsScreen][com.squareup.workflow1.ui.container.BodyAndOverlaysScreen]
* very soon.**
*
* May show a stack of [AlertScreen] over a [beneathModals].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi

/**
* **This will be deprecated in favor of
* [BodyAndModalsScreen][com.squareup.workflow1.ui.container.BodyAndModalsScreen]
* [BodyAndModalsScreen][com.squareup.workflow1.ui.container.BodyAndOverlaysScreen]
* very soon.**
*
* Interface implemented by screen classes that represent a stack of
Expand Down
Loading