Skip to content

Commit 9c29e1d

Browse files
WIP Add a config to use Compose for the runtime.
See go/compose-based-workflows.
1 parent d45a070 commit 9c29e1d

47 files changed

Lines changed: 2369 additions & 215 deletions

File tree

Some content is hidden

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

benchmarks/dungeon-benchmark/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ kotlin {
4848
}
4949

5050
dependencies {
51-
implementation(libs.androidx.macro.benchmark)
51+
implementation(libs.androidx.benchmark.macro)
5252
implementation(libs.androidx.test.espresso.core)
5353
implementation(libs.androidx.test.junit)
5454
implementation(libs.androidx.test.uiautomator)

benchmarks/performance-poetry/complex-benchmark/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ kotlin {
5757
}
5858

5959
dependencies {
60-
implementation(libs.androidx.macro.benchmark)
60+
implementation(libs.androidx.benchmark.macro)
6161
implementation(libs.androidx.test.espresso.core)
6262
implementation(libs.androidx.test.junit)
6363
implementation(libs.androidx.test.uiautomator)

benchmarks/performance-poetry/complex-poetry/src/main/java/com/squareup/benchmarks/performance/complex/poetry/instrumentation/PerformanceTracingInterceptor.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.squareup.benchmarks.performance.complex.poetry.instrumentation
33
import androidx.tracing.Trace
44
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemWorkflow
55
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowserWorkflow
6+
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.PerformanceTracingInterceptor.Companion.NODES_TO_TRACE
67
import com.squareup.workflow1.BaseRenderContext
78
import com.squareup.workflow1.WorkflowInterceptor
89
import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
@@ -27,6 +28,13 @@ class PerformanceTracingInterceptor(
2728
context: BaseRenderContext<P, S, O>,
2829
proceed: (P, S, RenderContextInterceptor<P, S, O>?) -> R,
2930
session: WorkflowSession
31+
): R = traceRender(session) {
32+
proceed(renderProps, renderState, null)
33+
}
34+
35+
private inline fun <R> traceRender(
36+
session: WorkflowSession,
37+
render: () -> R
3038
): R {
3139
val isRoot = session.parent == null
3240
val traceIdIndex = NODES_TO_TRACE.indexOfFirst { it.second == session.identifier }
@@ -45,7 +53,7 @@ class PerformanceTracingInterceptor(
4553
Trace.beginSection(sectionName)
4654
}
4755

48-
return proceed(renderProps, renderState, null).also {
56+
return render().also {
4957
if (traceIdIndex > -1 && !sample) {
5058
Trace.endSection()
5159
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ plugins {
2828
alias(libs.plugins.dokka)
2929
alias(libs.plugins.ktlint)
3030
alias(libs.plugins.compose.compiler) apply false
31+
alias(libs.plugins.androidx.benchmark) apply false
3132
}
3233

3334
shardConnectedCheckTasks(project)

gradle/libs.versions.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jdk-toolchain = "17"
1111

1212
androidx-activity = "1.8.2"
1313
androidx-appcompat = "1.7.0"
14-
androidx-benchmark = "1.3.3"
14+
androidx-benchmark = "1.3.4"
1515
androidx-cardview = "1.0.0"
1616
androidx-collection = "1.5.0"
1717
# see https://developer.android.com/jetpack/compose/bom/bom-mapping
@@ -98,11 +98,13 @@ timber = "5.0.1"
9898
truth = "1.4.4"
9999
turbine = "1.0.0"
100100
vanniktech-publish = "0.32.0"
101+
agp = "8.8.0"
101102

102103
[plugins]
103104
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
104105

105106
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
107+
androidx-benchmark = { id = "androidx.benchmark", version.ref = "androidx-benchmark" }
106108

107109
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
108110

@@ -116,6 +118,8 @@ kotlinx-apiBinaryCompatibility = { id = "org.jetbrains.kotlinx.binary-compatibil
116118
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
117119

118120
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose-plugin" }
121+
android-library = { id = "com.android.library", version.ref = "agp" }
122+
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
119123

120124
[libraries]
121125

@@ -167,7 +171,8 @@ androidx-lifecycle-viewmodel-core = { module = "androidx.lifecycle:lifecycle-vie
167171
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
168172
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle" }
169173

170-
androidx-macro-benchmark = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark" }
174+
androidx-benchmark = { module = "androidx.benchmark:benchmark-junit4", version.ref = "androidx-benchmark" }
175+
androidx-benchmark-macro = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark" }
171176

172177
androidx-profileinstaller = { module = "androidx.profileinstaller:profileinstaller", version.ref = "androidx-profileinstaller" }
173178

@@ -270,7 +275,7 @@ squareup-moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.re
270275

271276
squareup-okio = { module = "com.squareup.okio:okio", version.ref = "squareup-okio" }
272277

273-
squareup-papa = { module = "com.squareup.papa:papa", version.ref = "squareup-papa"}
278+
squareup-papa = { module = "com.squareup.papa:papa", version.ref = "squareup-papa" }
274279

275280
squareup-radiography = { module = "com.squareup.radiography:radiography", version.ref = "squareup-radiography" }
276281

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import androidx.compose.ui.platform.AndroidUiDispatcher
1111
import androidx.lifecycle.SavedStateHandle
1212
import androidx.lifecycle.ViewModel
1313
import androidx.lifecycle.viewModelScope
14+
import com.squareup.workflow1.RuntimeConfigOptions.COMPOSE_RUNTIME
15+
import com.squareup.workflow1.SimpleLoggingWorkflowInterceptor
1416
import com.squareup.workflow1.WorkflowExperimentalRuntime
1517
import com.squareup.workflow1.android.renderWorkflowIn
1618
import com.squareup.workflow1.config.AndroidRuntimeConfigTools
@@ -49,7 +51,8 @@ class NestedRenderingsActivity : AppCompatActivity() {
4951
workflow = RecursiveWorkflow.mapRendering { it.withEnvironment(viewEnvironment) },
5052
scope = viewModelScope + AndroidUiDispatcher.Main,
5153
savedStateHandle = savedState,
52-
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
54+
runtimeConfig = setOf(COMPOSE_RUNTIME), // AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
55+
interceptors = listOf(SimpleLoggingWorkflowInterceptor()),
5356
)
5457
}
5558
}

samples/containers/app-poetry/src/main/java/com/squareup/sample/poetryapp/PoetryActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.squareup.sample.container.SampleContainers
1212
import com.squareup.sample.poetry.RealPoemWorkflow
1313
import com.squareup.sample.poetry.RealPoemsBrowserWorkflow
1414
import com.squareup.sample.poetry.model.Poem
15+
import com.squareup.workflow1.RuntimeConfigOptions.COMPOSE_RUNTIME
1516
import com.squareup.workflow1.WorkflowExperimentalRuntime
1617
import com.squareup.workflow1.android.renderWorkflowIn
1718
import com.squareup.workflow1.config.AndroidRuntimeConfigTools
@@ -47,7 +48,7 @@ class PoetryModel(savedState: SavedStateHandle) : ViewModel() {
4748
scope = viewModelScope,
4849
prop = 0 to 0 to Poem.allPoems,
4950
savedStateHandle = savedState,
50-
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
51+
runtimeConfig = setOf(COMPOSE_RUNTIME), // AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
5152
).reportNavigation {
5253
Timber.i("Navigated to %s", it)
5354
}

samples/containers/app-raven/src/main/java/com/squareup/sample/ravenapp/RavenActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.lifecycle.viewModelScope
1212
import com.squareup.sample.container.SampleContainers
1313
import com.squareup.sample.poetry.RealPoemWorkflow
1414
import com.squareup.sample.poetry.model.Raven
15+
import com.squareup.workflow1.RuntimeConfigOptions.COMPOSE_RUNTIME
1516
import com.squareup.workflow1.WorkflowExperimentalRuntime
1617
import com.squareup.workflow1.android.renderWorkflowIn
1718
import com.squareup.workflow1.config.AndroidRuntimeConfigTools
@@ -56,7 +57,7 @@ class RavenModel(savedState: SavedStateHandle) : ViewModel() {
5657
scope = viewModelScope,
5758
savedStateHandle = savedState,
5859
prop = Raven,
59-
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
60+
runtimeConfig = setOf(COMPOSE_RUNTIME), // AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
6061
) {
6162
running.complete()
6263
}.reportNavigation {

samples/containers/hello-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModel
1010
import androidx.lifecycle.lifecycleScope
1111
import androidx.lifecycle.viewModelScope
1212
import com.squareup.sample.container.SampleContainers
13+
import com.squareup.workflow1.RuntimeConfigOptions.COMPOSE_RUNTIME
1314
import com.squareup.workflow1.WorkflowExperimentalRuntime
1415
import com.squareup.workflow1.android.renderWorkflowIn
1516
import com.squareup.workflow1.config.AndroidRuntimeConfigTools
@@ -53,7 +54,7 @@ class HelloBackButtonModel(savedState: SavedStateHandle) : ViewModel() {
5354
workflow = AreYouSureWorkflow,
5455
scope = viewModelScope,
5556
savedStateHandle = savedState,
56-
runtimeConfig = AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
57+
runtimeConfig = setOf(COMPOSE_RUNTIME), // AndroidRuntimeConfigTools.getAppWorkflowRuntimeConfig()
5758
) {
5859
// This workflow handles the back button itself, so the activity can't.
5960
// Instead, the workflow emits an output to signal that it's time to shut things down.

samples/dungeon/app/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("kotlin-android")
44
id("android-sample-app")
55
id("android-ui-tests")
6+
alias(libs.plugins.compose.compiler)
67
}
78

89
android {
@@ -43,12 +44,15 @@ dependencies {
4344
implementation(libs.rxjava2.rxandroid)
4445
implementation(libs.squareup.cycler)
4546
implementation(libs.squareup.okio)
47+
implementation(platform(libs.androidx.compose.bom))
48+
implementation(libs.androidx.compose.foundation)
4649

4750
implementation(project(":samples:dungeon:common"))
4851
implementation(project(":samples:dungeon:timemachine"))
4952
implementation(project(":samples:dungeon:timemachine-shakeable"))
5053
implementation(project(":workflow-ui:core-android"))
5154
implementation(project(":workflow-ui:core-common"))
55+
implementation(project(":workflow-ui:compose"))
5256

5357
testImplementation(libs.junit)
5458
testImplementation(libs.truth)

0 commit comments

Comments
 (0)