Skip to content

WIP: Exploring Compose Runtime Integration. #814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry

import androidx.compose.runtime.Composable
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.ActionHandlingTracingInterceptor
import com.squareup.benchmarks.performance.complex.poetry.instrumentation.asTraceableWorker
import com.squareup.benchmarks.performance.complex.poetry.views.LoaderSpinner
Expand All @@ -26,6 +27,7 @@ class MaybeLoadingGatekeeperWorkflow<T : Any>(
snapshot: Snapshot?
): IsLoading = false

@Composable
override fun render(
renderProps: Unit,
renderState: IsLoading,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry

import androidx.compose.runtime.Composable
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemWorkflow.Action.ClearSelection
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemWorkflow.Action.HandleStanzaListOutput
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemWorkflow.Action.SelectNext
Expand Down Expand Up @@ -90,6 +91,7 @@ class PerformancePoemWorkflow(
}

@OptIn(WorkflowUiExperimentalApi::class)
@Composable
override fun render(
renderProps: Poem,
renderState: State,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry

import androidx.compose.runtime.Composable
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowserWorkflow.State
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowserWorkflow.State.ComplexCall
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowserWorkflow.State.Initializing
Expand Down Expand Up @@ -71,6 +72,7 @@ class PerformancePoemsBrowserWorkflow(
}

@OptIn(WorkflowUiExperimentalApi::class)
@Composable
override fun render(
renderProps: List<Poem>,
renderState: State,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry.instrumentation

import androidx.compose.runtime.Composable
import androidx.tracing.trace
import com.squareup.workflow1.BaseRenderContext
import com.squareup.workflow1.WorkflowAction
Expand Down Expand Up @@ -56,11 +57,12 @@ class ActionHandlingTracingInterceptor : WorkflowInterceptor, Resettable {
}
}

@Composable
override fun <P, S, O, R> onRender(
renderProps: P,
renderState: S,
context: BaseRenderContext<P, S, O>,
proceed: (P, S, RenderContextInterceptor<P, S, O>?) -> R,
proceed: @Composable (P, S, RenderContextInterceptor<P, S, O>?) -> R,
session: WorkflowSession
): R {
return proceed(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry.instrumentation

import androidx.compose.runtime.Composable
import androidx.tracing.Trace
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemWorkflow
import com.squareup.benchmarks.performance.complex.poetry.PerformancePoemsBrowserWorkflow
Expand All @@ -21,11 +22,12 @@ class PerformanceTracingInterceptor(
) : WorkflowInterceptor, Resettable {
private var totalRenderPasses = 0

@Composable
override fun <P, S, O, R> onRender(
renderProps: P,
renderState: S,
context: BaseRenderContext<P, S, O>,
proceed: (P, S, RenderContextInterceptor<P, S, O>?) -> R,
proceed: @Composable (P, S, RenderContextInterceptor<P, S, O>?) -> R,
session: WorkflowSession
): R {
val isRoot = session.parent == null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.benchmarks.performance.complex.poetry.instrumentation

import androidx.compose.runtime.Composable
import com.squareup.workflow1.BaseRenderContext
import com.squareup.workflow1.WorkflowInterceptor
import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
Expand All @@ -18,11 +19,12 @@ class RenderPassCountingInterceptor : WorkflowInterceptor, Resettable {
lateinit var renderPassStats: RenderStats
private val nodeStates: MutableMap<Long, String> = mutableMapOf()

@Composable
override fun <P, S, O, R> onRender(
renderProps: P,
renderState: S,
context: BaseRenderContext<P, S, O>,
proceed: (P, S, RenderContextInterceptor<P, S, O>?) -> R,
proceed: @Composable (P, S, RenderContextInterceptor<P, S, O>?) -> R,
session: WorkflowSession
): R {
val isRoot = session.parent == null
Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
classpath(libs.kotlin.serialization.gradle.plugin)
classpath(libs.kotlinx.binaryCompatibility.gradle.plugin)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.molecule.gradle.plugin)
classpath(libs.google.ksp)
classpath(libs.ktlint.gradle)
classpath(libs.vanniktech.publish)
Expand All @@ -19,6 +20,9 @@ buildscript {
mavenCentral()
gradlePluginPortal()
google()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
// For binary compatibility validator.
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
}
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ plugins {
repositories {
mavenCentral()
google()
// For molecule SNAPSHOT
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
}

dependencies {
Expand Down
32 changes: 23 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ targetSdk = "30"
androidx-activity = "1.3.0"
androidx-appcompat = "1.3.1"
androidx-benchmark = "1.1.0-rc03"
androidx-compose = "1.1.0-rc01"
androidx-compose-compiler = "1.1.0-rc02"
compose = "1.1.0"
compose-compiler = "1.1.0"
androidx-constraintlayout = "2.1.2"
androidx-core = "1.6.0"
androidx-fragment = "1.3.6"
Expand Down Expand Up @@ -49,8 +49,8 @@ kotest = "5.1.0"
kotlin = "1.6.10"

kotlinx-binary-compatibility = "0.6.0"
kotlinx-coroutines = "1.5.1"
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
kotlinx-coroutines = "1.5.2"
# The 1.5.2 test artifact is jvm-only. The commonTest module should use 1.6.1.
kotlinx-coroutines-test-common = "1.6.1"
kotlinx-serialization-json = "1.3.2"
kotlinx-benchmark = "0.4.2"
Expand All @@ -64,6 +64,9 @@ mockito-core = "3.3.3"
mockito-kotlin = "3.2.0"

mockk = "1.11.0"

molecule = "0.3.0-SNAPSHOT"

robolectric = "4.6.1"

rxjava2-android = "2.1.1"
Expand Down Expand Up @@ -100,8 +103,12 @@ kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kot
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }

molecule = { id = "app.cash.molecule", version.ref = "molecule"}

[libraries]

molecule-gradle-plugin = { module = "app.cash.molecule:molecule-gradle-plugin", version.ref = "molecule"}

android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "androidTools" }

androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
Expand All @@ -112,13 +119,17 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a

androidx-macro-benchmark = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark" }

androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }

androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }

androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose" }
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "compose" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }

androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose" }
androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "androidx-compose" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
compose-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "compose"}
compose-compiler = { module = "org.jetbrains.compose.compiler:compiler", version.ref = "compose"}

androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "androidx-constraintlayout" }

Expand Down Expand Up @@ -203,6 +214,9 @@ mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "

mockk = { module = "io.mockk:mockk", version.ref = "mockk" }

molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule"}
molecule-testing = { module = "app.cash.molecule:molecule-testing", version.ref = "molecule"}

robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }

rxjava2-rxandroid = { module = "io.reactivex.rxjava2:rxandroid", version.ref = "rxjava2-android" }
Expand Down
2 changes: 1 addition & 1 deletion samples/compose-samples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.sample.poetry

import androidx.compose.runtime.Composable
import com.squareup.sample.poetry.StanzaListWorkflow.Props
import com.squareup.sample.poetry.model.Poem
import com.squareup.workflow1.StatelessWorkflow
Expand All @@ -20,6 +21,7 @@ object StanzaListWorkflow : StatelessWorkflow<Props, SelectedStanza, StanzaListS

const val NO_SELECTED_STANZA = -1

@Composable
override fun render(
renderProps: Props,
context: RenderContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squareup.sample.poetry

import androidx.compose.runtime.Composable
import com.squareup.sample.poetry.StanzaWorkflow.Output
import com.squareup.sample.poetry.StanzaWorkflow.Output.CloseStanzas
import com.squareup.sample.poetry.StanzaWorkflow.Output.ShowNextStanza
Expand All @@ -21,6 +22,7 @@ object StanzaWorkflow : StatelessWorkflow<Props, Output, StanzaScreen>() {
ShowNextStanza
}

@Composable
override fun render(
renderProps: Props,
context: RenderContext
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pluginManagement {
google()
// For binary compatibility validator.
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
// For molecule SNAPSHOT
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
}
}

Expand All @@ -29,6 +31,8 @@ dependencyResolutionManagement {
repositories {
mavenCentral()
google()
// For molecule SNAPSHOT
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/")}
// See androidx.dev (can use this for Snapshot builds of AndroidX)
// maven { url = java.net.URI.create("https://androidx.dev/snapshots/builds/8224905/artifacts/repository") }
}
Expand Down
6 changes: 5 additions & 1 deletion workflow-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
plugins {
`kotlin-multiplatform`
id("org.jetbrains.dokka")
id("app.cash.molecule")
}

apply(from = rootProject.file(".buildscript/configure-maven-publish.gradle"))

kotlin {
jvm { withJava() }
ios()
// ios()

sourceSets {
all {
Expand All @@ -19,15 +20,18 @@ kotlin {
dependencies {
api(libs.kotlin.jdk6)
api(libs.kotlinx.coroutines.core)
api(libs.compose.runtime)
// For Snapshot.
api(libs.squareup.okio)
implementation(libs.molecule.runtime)
}
}
val commonTest by getting {
dependencies {
implementation(libs.kotlinx.atomicfu)
implementation(libs.kotlinx.coroutines.test.common)
implementation(libs.kotlin.test.jdk)
implementation(libs.molecule.testing)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.squareup.workflow1

import androidx.compose.runtime.Composable
import com.squareup.workflow1.WorkflowAction.Companion.noAction
import kotlinx.coroutines.CoroutineScope
import kotlin.jvm.JvmMultifileClass
Expand Down Expand Up @@ -71,6 +72,7 @@ public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
* @param key An optional string key that is used to distinguish between workflows of the same
* type.
*/
@Composable
public fun <ChildPropsT, ChildOutputT, ChildRenderingT> renderChild(
child: Workflow<ChildPropsT, ChildOutputT, ChildRenderingT>,
props: ChildPropsT,
Expand Down Expand Up @@ -217,6 +219,7 @@ public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
/**
* Convenience alias of [BaseRenderContext.renderChild] for workflows that don't take props.
*/
@Composable
public fun <PropsT, StateT, OutputT, ChildOutputT, ChildRenderingT>
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
child: Workflow<Unit, ChildOutputT, ChildRenderingT>,
Expand All @@ -226,6 +229,7 @@ BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
/**
* Convenience alias of [BaseRenderContext.renderChild] for workflows that don't emit output.
*/
@Composable
public fun <PropsT, ChildPropsT, StateT, OutputT, ChildRenderingT>
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
child: Workflow<ChildPropsT, Nothing, ChildRenderingT>,
Expand All @@ -236,6 +240,7 @@ BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
* Convenience alias of [BaseRenderContext.renderChild] for children that don't take props or emit
* output.
*/
@Composable
public fun <PropsT, StateT, OutputT, ChildRenderingT>
BaseRenderContext<PropsT, StateT, OutputT>.renderChild(
child: Workflow<Unit, Nothing, ChildRenderingT>,
Expand Down
Loading