Skip to content

Commit f82f32f

Browse files
authored
Merge pull request #577 from square/ray/introducing-Screen
Introduces Screen, WithEnvironment : Screen. Deprecates ViewFactory
2 parents 3721c67 + 3f479a8 commit f82f32f

File tree

165 files changed

+3152
-1687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+3152
-1687
lines changed

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.sample.compose.hellocomposebinding
24

35
import android.os.Bundle

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.sample.compose.hellocomposeworkflow
24

35
import android.os.Bundle

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.sample.compose.inlinerendering
24

35
import android.os.Bundle

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@file:Suppress("DEPRECATION")
12
@file:OptIn(WorkflowUiExperimentalApi::class)
23

34
package com.squareup.sample.compose.inlinerendering

samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/LegacyRunner.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.sample.compose.nestedrenderings
24

35
import androidx.compose.foundation.layout.fillMaxSize

samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package com.squareup.sample.compose.nestedrenderings
24

35
import android.os.Bundle

samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.squareup.sample.container
22

3+
import com.squareup.workflow1.ui.Screen
34
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
45

56
/**
@@ -16,8 +17,8 @@ import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1617
* is pressed, or null to set no handler. Defaults to `null`.
1718
*/
1819
@WorkflowUiExperimentalApi
19-
data class BackButtonScreen<W : Any>(
20+
data class BackButtonScreen<W : Screen>(
2021
val wrapped: W,
2122
val override: Boolean = false,
2223
val onBackPressed: (() -> Unit)? = null
23-
)
24+
) : Screen
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package com.squareup.sample.container
22

3-
import com.squareup.workflow1.ui.DecorativeViewFactory
4-
import com.squareup.workflow1.ui.ViewFactory
3+
import com.squareup.workflow1.ui.DecorativeScreenViewFactory
4+
import com.squareup.workflow1.ui.ScreenViewFactory
55
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
66
import com.squareup.workflow1.ui.backPressedHandler
77

88
/**
9-
* [ViewFactory] that performs the work required by [BackButtonScreen].
9+
* [ScreenViewFactory] that performs the work required by [BackButtonScreen].
1010
*/
1111
@WorkflowUiExperimentalApi
12-
object BackButtonViewFactory : ViewFactory<BackButtonScreen<*>>
13-
by DecorativeViewFactory(
14-
type = BackButtonScreen::class,
15-
map = { outer -> outer.wrapped },
16-
doShowRendering = { view, innerShowRendering, outerRendering, viewEnvironment ->
17-
if (!outerRendering.override) {
18-
// Place our handler before invoking innerShowRendering, so that
19-
// its later calls to view.backPressedHandler will take precedence
20-
// over ours.
21-
view.backPressedHandler = outerRendering.onBackPressed
22-
}
12+
object BackButtonViewFactory : ScreenViewFactory<BackButtonScreen<*>>
13+
by DecorativeScreenViewFactory(
14+
type = BackButtonScreen::class,
15+
map = { outer -> outer.wrapped },
16+
doShowRendering = { view, innerShowRendering, outerRendering, viewEnvironment ->
17+
if (!outerRendering.override) {
18+
// Place our handler before invoking innerShowRendering, so that
19+
// its later calls to view.backPressedHandler will take precedence
20+
// over ours.
21+
view.backPressedHandler = outerRendering.onBackPressed
22+
}
2323

24-
innerShowRendering.invoke(outerRendering.wrapped, viewEnvironment)
24+
innerShowRendering.invoke(outerRendering.wrapped, viewEnvironment)
2525

26-
if (outerRendering.override) {
27-
// Place our handler after invoking innerShowRendering, so that ours wins.
28-
view.backPressedHandler = outerRendering.onBackPressed
29-
}
30-
})
26+
if (outerRendering.override) {
27+
// Place our handler after invoking innerShowRendering, so that ours wins.
28+
view.backPressedHandler = outerRendering.onBackPressed
29+
}
30+
}
31+
)

samples/containers/android/src/main/java/com/squareup/sample/container/overviewdetail/OverviewDetailContainer.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import com.squareup.sample.container.R
77
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Detail
88
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Overview
99
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Single
10-
import com.squareup.workflow1.ui.LayoutRunner
10+
import com.squareup.workflow1.ui.ScreenViewFactory
11+
import com.squareup.workflow1.ui.ScreenViewRunner
1112
import com.squareup.workflow1.ui.ViewEnvironment
12-
import com.squareup.workflow1.ui.ViewFactory
1313
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1414
import com.squareup.workflow1.ui.WorkflowViewStub
15-
import com.squareup.workflow1.ui.backstack.BackStackScreen
16-
import com.squareup.workflow1.ui.backstack.withBackStackStateKeyPrefix
15+
import com.squareup.workflow1.ui.container.BackStackScreen
16+
import com.squareup.workflow1.ui.container.withBackStackStateKeyPrefix
1717

1818
/**
1919
* Displays [OverviewDetailScreen] renderings in either split pane or single pane
@@ -25,7 +25,7 @@ import com.squareup.workflow1.ui.backstack.withBackStackStateKeyPrefix
2525
* with [OverviewDetailScreen.overviewRendering] as the base of the stack.
2626
*/
2727
@OptIn(WorkflowUiExperimentalApi::class)
28-
class OverviewDetailContainer(view: View) : LayoutRunner<OverviewDetailScreen> {
28+
class OverviewDetailContainer(view: View) : ScreenViewRunner<OverviewDetailScreen> {
2929

3030
private val overviewStub: WorkflowViewStub? = view.findViewById(R.id.overview_stub)
3131
private val detailStub: WorkflowViewStub? = view.findViewById(R.id.detail_stub)
@@ -53,15 +53,15 @@ class OverviewDetailContainer(view: View) : LayoutRunner<OverviewDetailScreen> {
5353
if (rendering.detailRendering == null && rendering.selectDefault != null) {
5454
rendering.selectDefault!!.invoke()
5555
} else {
56-
// Since we have two sibling backstacks, we need to give them each different
56+
// Since we have two sibling back stacks, we need to give them each different
5757
// SavedStateRegistry key prefixes.
5858
val overviewViewEnvironment = viewEnvironment
5959
.withBackStackStateKeyPrefix(OverviewBackStackKey) + (OverviewDetailConfig to Overview)
60-
overviewStub!!.update(rendering.overviewRendering, overviewViewEnvironment)
60+
overviewStub!!.show(rendering.overviewRendering, overviewViewEnvironment)
6161
rendering.detailRendering
6262
?.let { detail ->
6363
detailStub!!.actual.visibility = VISIBLE
64-
detailStub.update(
64+
detailStub.show(
6565
detail,
6666
viewEnvironment + (OverviewDetailConfig to Detail)
6767
)
@@ -81,10 +81,10 @@ class OverviewDetailContainer(view: View) : LayoutRunner<OverviewDetailScreen> {
8181
?.let { rendering.overviewRendering + it }
8282
?: rendering.overviewRendering
8383

84-
stub.update(combined, viewEnvironment + (OverviewDetailConfig to Single))
84+
stub.show(combined, viewEnvironment + (OverviewDetailConfig to Single))
8585
}
8686

87-
companion object : ViewFactory<OverviewDetailScreen> by LayoutRunner.bind(
87+
companion object : ScreenViewFactory<OverviewDetailScreen> by ScreenViewRunner.bind(
8888
layoutId = R.layout.overview_detail,
8989
constructor = ::OverviewDetailContainer
9090
) {

samples/containers/android/src/main/java/com/squareup/sample/container/panel/PanelContainer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import android.view.View
1010
import android.view.ViewGroup
1111
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
1212
import com.squareup.sample.container.R
13-
import com.squareup.workflow1.ui.BuilderViewFactory
14-
import com.squareup.workflow1.ui.ViewFactory
13+
import com.squareup.workflow1.ui.ManualScreenViewFactory
14+
import com.squareup.workflow1.ui.ScreenViewFactory
1515
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1616
import com.squareup.workflow1.ui.bindShowRendering
1717
import com.squareup.workflow1.ui.modal.ModalViewContainer
@@ -59,7 +59,7 @@ class PanelContainer @JvmOverloads constructor(
5959
}
6060
}
6161

62-
companion object : ViewFactory<PanelContainerScreen<*, *>> by BuilderViewFactory(
62+
companion object : ScreenViewFactory<PanelContainerScreen<*, *>> by ManualScreenViewFactory(
6363
type = PanelContainerScreen::class,
6464
viewConstructor = { initialRendering, initialEnv, contextForNewView, _ ->
6565
PanelContainer(contextForNewView).apply {

0 commit comments

Comments
 (0)