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,8 +3,8 @@ package com.squareup.workflow1.ui
import android.view.View
import com.squareup.workflow1.ui.container.BackStackScreen
import com.squareup.workflow1.ui.container.BackStackScreenViewFactory
import com.squareup.workflow1.ui.container.WithEnvironmentViewFactory
import com.squareup.workflow1.ui.container.WithEnvironment
import com.squareup.workflow1.ui.container.EnvironmentScreenViewFactory
import com.squareup.workflow1.ui.container.EnvironmentScreen

/**
* It is usually more convenient to use [WorkflowViewStub] or [DecorativeScreenViewFactory]
Expand Down Expand Up @@ -42,8 +42,8 @@ public fun <ScreenT : Screen>
BackStackScreenViewFactory as ScreenViewFactory<ScreenT>
}
?: (rendering as? NamedScreen<*>)?.let { NamedScreenViewFactory as ScreenViewFactory<ScreenT> }
?: (rendering as? WithEnvironment<*>)?.let {
WithEnvironmentViewFactory as ScreenViewFactory<ScreenT>
?: (rendering as? EnvironmentScreen<*>)?.let {
EnvironmentScreenViewFactory as ScreenViewFactory<ScreenT>
}
?: throw IllegalArgumentException(
"A ScreenViewFactory should have been registered to display $rendering, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.FrameLayout
import com.squareup.workflow1.ui.container.WithEnvironment
import com.squareup.workflow1.ui.container.EnvironmentScreen
import com.squareup.workflow1.ui.container.withEnvironment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -22,7 +22,7 @@ import kotlinx.coroutines.flow.onEach

/**
* A view that can be driven by a stream of [Screen] renderings passed to its [take] method.
* To configure the [ViewEnvironment] in play, use [WithEnvironment] as your root rendering type.
* To configure the [ViewEnvironment] in play, use [EnvironmentScreen] as your root rendering type.
*
* [id][setId] defaults to [R.id.workflow_layout], as a convenience to ensure that
* view persistence will work without requiring authors to be immersed in Android arcana.
Expand All @@ -49,11 +49,11 @@ public class WorkflowLayout(
/**
* While this view is attached to a window, subscribes to [renderings] and display its values.
*
* To configure the [ViewEnvironment], use [WithEnvironment] as your rendering type.
* To configure the [ViewEnvironment], use [EnvironmentScreen] as your rendering type.
* For example, to customize the UI via [ViewRegistry] entries:
*
* val registry = ViewRegistry(MuchBetterViewForFooScreen)
* val renderings: Flow<WithEnvironment<*>> = renderWorkflowIn(...).map {
* val renderings: Flow<EnvironmentScreen<*>> = renderWorkflowIn(...).map {
* it.withRegistry(registry)
* }
* workflowLayout.take(renderings)
Expand Down Expand Up @@ -102,7 +102,7 @@ public class WorkflowLayout(
}
}

private fun show(rootScreen: WithEnvironment<*>) {
private fun show(rootScreen: EnvironmentScreen<*>) {
showing.show(rootScreen.screen, rootScreen.viewEnvironment)
restoredChildState?.let { restoredState ->
restoredChildState = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.updateFrom

@WorkflowUiExperimentalApi
internal object WithEnvironmentViewFactory : ScreenViewFactory<WithEnvironment<*>>
internal object EnvironmentScreenViewFactory : ScreenViewFactory<EnvironmentScreen<*>>
by DecorativeScreenViewFactory(
type = WithEnvironment::class,
type = EnvironmentScreen::class,
map = { withEnvironment, inheritedEnvironment ->
Pair(
withEnvironment.screen,
Expand Down
12 changes: 6 additions & 6 deletions workflow-ui/core-common/api/core-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ public final class com/squareup/workflow1/ui/container/BackStackScreenKt {
public static final fun toBackStackScreenOrNull (Ljava/util/List;)Lcom/squareup/workflow1/ui/container/BackStackScreen;
}

public final class com/squareup/workflow1/ui/container/WithEnvironment : com/squareup/workflow1/ui/Compatible, com/squareup/workflow1/ui/Screen {
public final class com/squareup/workflow1/ui/container/EnvironmentScreen : com/squareup/workflow1/ui/Compatible, com/squareup/workflow1/ui/Screen {
public fun getCompatibilityKey ()Ljava/lang/String;
public final fun getScreen ()Lcom/squareup/workflow1/ui/Screen;
public final fun getViewEnvironment ()Lcom/squareup/workflow1/ui/ViewEnvironment;
}

public final class com/squareup/workflow1/ui/container/WithEnvironmentKt {
public static final fun plus (Lcom/squareup/workflow1/ui/container/WithEnvironment;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/WithEnvironment;
public static final fun withEnvironment (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/WithEnvironment;
public static synthetic fun withEnvironment$default (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/WithEnvironment;
public static final fun withRegistry (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/container/WithEnvironment;
public final class com/squareup/workflow1/ui/container/EnvironmentScreenKt {
public static final fun plus (Lcom/squareup/workflow1/ui/container/EnvironmentScreen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen;
public static final fun withEnvironment (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen;
public static synthetic fun withEnvironment$default (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewEnvironment;ILjava/lang/Object;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen;
public static final fun withRegistry (Lcom/squareup/workflow1/ui/Screen;Lcom/squareup/workflow1/ui/ViewRegistry;)Lcom/squareup/workflow1/ui/container/EnvironmentScreen;
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,46 @@ import com.squareup.workflow1.ui.updateFrom
* Use [withEnvironment] or [withRegistry] to create or update instances.
*/
@WorkflowUiExperimentalApi
public class WithEnvironment<V : Screen> internal constructor(
public class EnvironmentScreen<V : Screen> internal constructor(
public val screen: V,
public val viewEnvironment: ViewEnvironment = ViewEnvironment()
) : Compatible, Screen {
/**
* Ensures that we make the decision to update or replace the root view based on
* the wrapped [screen].
*/
override val compatibilityKey: String = Compatible.keyFor(screen, "WithEnvironment")
override val compatibilityKey: String = Compatible.keyFor(screen, "EnvironmentScreen")
}

@WorkflowUiExperimentalApi
public operator fun <T : Screen> WithEnvironment<T>.plus(
public operator fun <T : Screen> EnvironmentScreen<T>.plus(
environment: ViewEnvironment
): WithEnvironment<T> {
): EnvironmentScreen<T> {
return when {
environment.map.isEmpty() -> this
else -> WithEnvironment(screen, viewEnvironment.updateFrom(environment))
else -> EnvironmentScreen(screen, viewEnvironment.updateFrom(environment))
}
}

/**
* Returns a [WithEnvironment] derived from the receiver, whose [ViewEnvironment]
* Returns a [EnvironmentScreen] derived from the receiver, whose [ViewEnvironment]
* includes a [ViewRegistry] updated from the given [viewRegistry].
*/
@WorkflowUiExperimentalApi
public fun Screen.withRegistry(viewRegistry: ViewRegistry): WithEnvironment<*> {
public fun Screen.withRegistry(viewRegistry: ViewRegistry): EnvironmentScreen<*> {
return withEnvironment(ViewEnvironment(mapOf(ViewRegistry to viewRegistry)))
}

/**
* Returns a [WithEnvironment] derived from the receiver, whose [ViewEnvironment]
* Returns a [EnvironmentScreen] derived from the receiver, whose [ViewEnvironment]
* is [updated][updateFrom] the given [viewEnvironment].
*/
@WorkflowUiExperimentalApi
public fun Screen.withEnvironment(
viewEnvironment: ViewEnvironment = ViewEnvironment()
): WithEnvironment<*> {
): EnvironmentScreen<*> {
return when (this) {
is WithEnvironment<*> -> this + viewEnvironment
else -> WithEnvironment(this, viewEnvironment)
is EnvironmentScreen<*> -> this + viewEnvironment
else -> EnvironmentScreen(this, viewEnvironment)
}
}