diff --git a/kotlin/.buildscript/configure-compose.gradle b/kotlin/.buildscript/configure-compose.gradle index 666952ff4..7534e01d6 100644 --- a/kotlin/.buildscript/configure-compose.gradle +++ b/kotlin/.buildscript/configure-compose.gradle @@ -14,11 +14,23 @@ * limitations under the License. */ +/* +In addition applying this file, as of dev10 modules that use Compose also need to include this +code snippet to avoid warnings about using compiler version 1.4 (this is because the compiler plugin +is built against compiler source that is in a liminal state between 1.3 and 1.4, the warnings are +safe to ignore and this suppresses them): + +tasks.withType().configureEach { + kotlinOptions.apiVersion = "1.3" +} +*/ + android { buildFeatures { compose true } composeOptions { + kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424" kotlinCompilerExtensionVersion Versions.compose } } diff --git a/kotlin/buildSrc/src/main/java/Dependencies.kt b/kotlin/buildSrc/src/main/java/Dependencies.kt index a65cf0238..53b1554b4 100644 --- a/kotlin/buildSrc/src/main/java/Dependencies.kt +++ b/kotlin/buildSrc/src/main/java/Dependencies.kt @@ -4,7 +4,7 @@ import java.util.Locale.US import kotlin.reflect.full.declaredMembers object Versions { - const val compose = "0.1.0-dev09" + const val compose = "0.1.0-dev10" const val coroutines = "1.3.4" const val kotlin = "1.3.71" const val targetSdk = 29 diff --git a/kotlin/samples/hello-compose-binding/build.gradle.kts b/kotlin/samples/hello-compose-binding/build.gradle.kts index 1f5e48cef..dd5982138 100644 --- a/kotlin/samples/hello-compose-binding/build.gradle.kts +++ b/kotlin/samples/hello-compose-binding/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + /* * Copyright 2019 Square Inc. * @@ -28,6 +30,9 @@ android { } apply(from = rootProject.file(".buildscript/configure-compose.gradle")) +tasks.withType { + kotlinOptions.apiVersion = "1.3" +} dependencies { implementation(project(":workflow-ui:core-compose")) diff --git a/kotlin/samples/hello-compose-binding/src/androidTest/java/com/squareup/sample/hellocomposebinding/HelloBindingTest.kt b/kotlin/samples/hello-compose-binding/src/androidTest/java/com/squareup/sample/hellocomposebinding/HelloBindingTest.kt index fb6ec10cf..9723cbf5d 100644 --- a/kotlin/samples/hello-compose-binding/src/androidTest/java/com/squareup/sample/hellocomposebinding/HelloBindingTest.kt +++ b/kotlin/samples/hello-compose-binding/src/androidTest/java/com/squareup/sample/hellocomposebinding/HelloBindingTest.kt @@ -15,8 +15,8 @@ */ package com.squareup.sample.hellocomposebinding -import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.ui.test.android.AndroidComposeTestRule import androidx.ui.test.assertIsDisplayed import androidx.ui.test.doClick import androidx.ui.test.findByText @@ -28,7 +28,7 @@ import org.junit.runner.RunWith class HelloBindingTest { // Launches the activity. - @Rule @JvmField val scenario = ActivityScenarioRule(HelloBindingActivity::class.java) + @Rule @JvmField val composeRule = AndroidComposeTestRule() @Test fun togglesBetweenStates() { findByText("Hello") diff --git a/kotlin/workflow-ui/core-compose/README.md b/kotlin/workflow-ui/core-compose/README.md index 3ad7e61f3..5235c1ed9 100644 --- a/kotlin/workflow-ui/core-compose/README.md +++ b/kotlin/workflow-ui/core-compose/README.md @@ -29,21 +29,28 @@ android { compose true } composeOptions { + kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424" kotlinCompilerExtensionVersion "${compose_version}" } } ``` -To create a binding, call `bindCompose`. The lambda passed to `bindCompose` is a `@Composable` +You may also need to set the Kotlin API version to 1.3: + +```groovy +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions.apiVersion = "1.3" +} +``` + +To create a `ViewFactory`, call `bindCompose`. The lambda passed to `bindCompose` is a `@Composable` function. ```kotlin val HelloBinding = bindCompose { rendering -> MaterialTheme { Clickable(onClick = { rendering.onClick() }) { - Center { - Text(rendering.message) - } + Text(rendering.message) } } } @@ -57,5 +64,5 @@ val viewRegistry = ViewRegistry(HelloBinding) ``` [1]: https://developer.android.com/jetpack/compose -[2]: https://square.github.io/workflow/kotlin/api/workflow-ui-android/com.squareup.workflow.ui/-view-binding/ -[3]: https://square.github.io/workflow/kotlin/api/workflow-ui-android/com.squareup.workflow.ui/-view-registry/ +[2]: https://square.github.io/workflow/kotlin/api/workflow/com.squareup.workflow.ui/-view-factory/ +[3]: https://square.github.io/workflow/kotlin/api/workflow/com.squareup.workflow.ui/-view-registry/ diff --git a/kotlin/workflow-ui/core-compose/build.gradle.kts b/kotlin/workflow-ui/core-compose/build.gradle.kts index a197c8969..359c6257e 100644 --- a/kotlin/workflow-ui/core-compose/build.gradle.kts +++ b/kotlin/workflow-ui/core-compose/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + /* * Copyright 2019 Square Inc. * @@ -24,10 +26,12 @@ java { } apply(from = rootProject.file(".buildscript/configure-maven-publish.gradle")) - apply(from = rootProject.file(".buildscript/configure-android-defaults.gradle")) apply(from = rootProject.file(".buildscript/configure-compose.gradle")) +tasks.withType { + kotlinOptions.apiVersion = "1.3" +} dependencies { api(project(":workflow-ui:core-android")) diff --git a/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt b/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt index c7116d231..b095f296f 100644 --- a/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt +++ b/kotlin/workflow-ui/core-compose/src/main/java/com/squareup/workflow/ui/compose/ComposeViewFactory.kt @@ -23,6 +23,7 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import androidx.compose.Composable +import androidx.compose.Recomposer import androidx.compose.StructurallyEqual import androidx.compose.mutableStateOf import androidx.ui.core.setContent @@ -84,7 +85,7 @@ internal class ComposeViewFactory( ) // Entry point to the composition. - composeContainer.setContent { + composeContainer.setContent(Recomposer.current()) { // Don't compose anything until we have the first value (which should happen in the initial // frame). val (rendering, environment) = renderState.value ?: return@setContent