Skip to content

Commit

Permalink
Merge pull request #1118 from square/zachklipp/compose-dev10
Browse files Browse the repository at this point in the history
Update Compose to dev10.
  • Loading branch information
zach-klippenstein authored May 4, 2020
2 parents 3350aff + d28651b commit fa8e89f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
12 changes: 12 additions & 0 deletions kotlin/.buildscript/configure-compose.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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<KotlinCompile>().configureEach {
kotlinOptions.apiVersion = "1.3"
}
*/

android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion Versions.compose
}
}
2 changes: 1 addition & 1 deletion kotlin/buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions kotlin/samples/hello-compose-binding/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/*
* Copyright 2019 Square Inc.
*
Expand Down Expand Up @@ -28,6 +30,9 @@ android {
}

apply(from = rootProject.file(".buildscript/configure-compose.gradle"))
tasks.withType<KotlinCompile> {
kotlinOptions.apiVersion = "1.3"
}

dependencies {
implementation(project(":workflow-ui:core-compose"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<HelloBindingActivity>()

@Test fun togglesBetweenStates() {
findByText("Hello")
Expand Down
19 changes: 13 additions & 6 deletions kotlin/workflow-ui/core-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyRendering> { rendering ->
MaterialTheme {
Clickable(onClick = { rendering.onClick() }) {
Center {
Text(rendering.message)
}
Text(rendering.message)
}
}
}
Expand All @@ -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/
6 changes: 5 additions & 1 deletion kotlin/workflow-ui/core-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/*
* Copyright 2019 Square Inc.
*
Expand All @@ -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<KotlinCompile> {
kotlinOptions.apiVersion = "1.3"
}

dependencies {
api(project(":workflow-ui:core-android"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +85,7 @@ internal class ComposeViewFactory<RenderingT : Any>(
)

// 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
Expand Down

0 comments on commit fa8e89f

Please sign in to comment.