Skip to content

Commit 3d5838e

Browse files
Merge pull request #56 from square/wardell/compose-dev15-update
Update Jetpack Compose to dev15
2 parents a4636fc + 86f4b54 commit 3d5838e

File tree

30 files changed

+201
-420
lines changed

30 files changed

+201
-420
lines changed

.buildscript/configure-compose.gradle

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
/*
18-
In addition applying this file, as of dev10 modules that use Compose also need to include this
19-
code snippet to avoid warnings about using compiler version 1.4 (this is because the compiler plugin
20-
is built against compiler source that is in a liminal state between 1.3 and 1.4, the warnings are
21-
safe to ignore and this suppresses them):
22-
23-
tasks.withType<KotlinCompile>().configureEach {
24-
kotlinOptions.apiVersion = "1.3"
25-
}
26-
*/
27-
2817
android {
2918
buildFeatures {
3019
compose true
3120
}
3221
composeOptions {
33-
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
22+
kotlinCompilerVersion "1.4.0-dev-withExperimentalGoogleExtensions-20200720"
3423
kotlinCompilerExtensionVersion Versions.compose
3524
}
3625
}

README.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,12 @@ android {
4848
compose true
4949
}
5050
composeOptions {
51-
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
51+
kotlinCompilerVersion "1.4.0-dev-withExperimentalGoogleExtensions-20200720"
5252
kotlinCompilerExtensionVersion "${compose_version}"
5353
}
5454
}
5555
```
5656

57-
You may also need to set the Kotlin API version to 1.3:
58-
59-
```groovy
60-
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
61-
kotlinOptions.apiVersion = "1.3"
62-
}
63-
```
64-
6557
To create a `ViewFactory`, call `composedViewFactory`. The lambda passed to `composedViewFactory` is
6658
a `@Composable` function.
6759

build.gradle.kts

+13-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ buildscript {
3333
mavenCentral()
3434
gradlePluginPortal()
3535
google()
36+
// For Kotlin 1.4.
37+
maven("https://dl.bintray.com/kotlin/kotlin-eap")
3638
// For binary compatibility validator.
37-
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
39+
maven("https://kotlin.bintray.com/kotlinx")
3840
}
3941
}
4042

@@ -46,6 +48,8 @@ subprojects {
4648
google()
4749
mavenCentral()
4850
jcenter()
51+
// For Kotlin 1.4.
52+
maven("https://dl.bintray.com/kotlin/kotlin-eap")
4953
}
5054

5155
configurations.all {
@@ -84,8 +88,14 @@ subprojects {
8488
jvmTarget = "1.8"
8589

8690
// Don't panic, all this does is allow us to use the @OptIn meta-annotation.
87-
// to define our own experiments.
88-
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
91+
// to define our own experiments, and some required args for compose dev15 taken from
92+
// https://developer.android.com/jetpack/androidx/releases/compose-runtime
93+
freeCompilerArgs += listOf(
94+
"-Xopt-in=kotlin.RequiresOptIn",
95+
"-Xallow-jvm-ir-dependencies",
96+
"-Xskip-prerelease-check"
97+
)
98+
8999
}
90100
}
91101

buildSrc/src/main/java/Dependencies.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,26 @@ import java.util.Locale.US
1919
import kotlin.reflect.full.declaredMembers
2020

2121
object Versions {
22-
const val compose = "0.1.0-dev12"
23-
const val kotlin = "1.3.71"
22+
const val compose = "0.1.0-dev15"
23+
const val kotlin = "1.4-M3"
2424
const val targetSdk = 29
2525
const val workflow = "0.28.0"
2626
}
2727

2828
@Suppress("unused")
2929
object Dependencies {
30-
const val android_gradle_plugin = "com.android.tools.build:gradle:4.2.0-alpha01"
30+
const val android_gradle_plugin = "com.android.tools.build:gradle:4.2.0-alpha05"
3131

3232
object AndroidX {
3333
const val appcompat = "androidx.appcompat:appcompat:1.1.0"
3434
}
3535

3636
object Compose {
37-
const val foundation = "androidx.ui:ui-foundation:${Versions.compose}"
38-
const val layout = "androidx.ui:ui-layout:${Versions.compose}"
39-
const val material = "androidx.ui:ui-material:${Versions.compose}"
40-
const val savedstate = "androidx.ui:ui-saved-instance-state:${Versions.compose}"
37+
const val foundation = "androidx.compose.foundation:foundation:${Versions.compose}"
38+
const val layout = "androidx.compose.foundation:foundation-layout:${Versions.compose}"
39+
const val material = "androidx.compose.material:material:${Versions.compose}"
40+
const val savedstate =
41+
"androidx.compose.runtime:runtime-saved-instance-state:${Versions.compose}"
4142
const val test = "androidx.ui:ui-test:${Versions.compose}"
4243
const val tooling = "androidx.ui:ui-tooling:${Versions.compose}"
4344
}

compose-tooling/build.gradle.kts

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
21

32
/*
43
* Copyright 2020 Square Inc.
@@ -30,9 +29,6 @@ apply(from = rootProject.file(".buildscript/configure-android-defaults.gradle"))
3029
apply(from = rootProject.file(".buildscript/android-ui-tests.gradle"))
3130

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

3733
dependencies {
3834
api(project(":core-compose"))

compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewComposeWorkflowTest.kt

+15-22
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import androidx.ui.core.Modifier
2323
import androidx.ui.foundation.Text
2424
import androidx.ui.layout.Column
2525
import androidx.ui.layout.size
26-
import androidx.ui.semantics.Semantics
2726
import androidx.ui.test.assertIsDisplayed
2827
import androidx.ui.test.assertIsNotDisplayed
2928
import androidx.ui.test.createComposeRule
30-
import androidx.ui.test.findByText
29+
import androidx.ui.test.onNodeWithText
3130
import androidx.ui.tooling.preview.Preview
3231
import androidx.ui.unit.dp
3332
import com.squareup.workflow.Workflow
@@ -39,7 +38,7 @@ import org.junit.Test
3938
import org.junit.runner.RunWith
4039

4140
/**
42-
* Duplicate of [PreviewViewFactoryTest] but for [com.squareup.workflow.compose.ComposeWorkflow].
41+
* Duplicate of [PreviewViewFactoryTest] but for [com.squareup.workflow.ui.compose.ComposeWorkflow].
4342
*/
4443
@RunWith(AndroidJUnit4::class)
4544
class PreviewComposeWorkflowTest {
@@ -51,18 +50,18 @@ class PreviewComposeWorkflowTest {
5150
ParentWithOneChildPreview()
5251
}
5352

54-
findByText("one").assertIsDisplayed()
55-
findByText("two").assertIsDisplayed()
53+
onNodeWithText("one").assertIsDisplayed()
54+
onNodeWithText("two").assertIsDisplayed()
5655
}
5756

5857
@Test fun twoChildren() {
5958
composeRule.setContent {
6059
ParentWithTwoChildrenPreview()
6160
}
6261

63-
findByText("one").assertIsDisplayed()
64-
findByText("two").assertIsDisplayed()
65-
findByText("three").assertIsDisplayed()
62+
onNodeWithText("one").assertIsDisplayed()
63+
onNodeWithText("two").assertIsDisplayed()
64+
onNodeWithText("three").assertIsDisplayed()
6665
}
6766

6867
@Test fun modifierIsApplied() {
@@ -71,8 +70,8 @@ class PreviewComposeWorkflowTest {
7170
}
7271

7372
// The view factory will be rendered with size (0,0), so it should be reported as not displayed.
74-
findByText("one").assertIsNotDisplayed()
75-
findByText("two").assertIsNotDisplayed()
73+
onNodeWithText("one").assertIsNotDisplayed()
74+
onNodeWithText("two").assertIsNotDisplayed()
7675
}
7776

7877
@Test fun placeholderModifierIsApplied() {
@@ -81,25 +80,23 @@ class PreviewComposeWorkflowTest {
8180
}
8281

8382
// The child will be rendered with size (0,0), so it should be reported as not displayed.
84-
findByText("one").assertIsDisplayed()
85-
findByText("two").assertIsNotDisplayed()
83+
onNodeWithText("one").assertIsDisplayed()
84+
onNodeWithText("two").assertIsNotDisplayed()
8685
}
8786

8887
@Test fun customViewEnvironment() {
8988
composeRule.setContent {
9089
ParentConsumesCustomKeyPreview()
9190
}
9291

93-
findByText("foo").assertIsDisplayed()
92+
onNodeWithText("foo").assertIsDisplayed()
9493
}
9594

9695
private val ParentWithOneChild =
9796
Workflow.composed<Pair<String, String>, Nothing> { props, _, environment ->
9897
Column {
9998
Text(props.first)
100-
Semantics(container = true, mergeAllDescendants = true) {
101-
WorkflowRendering(props.second, environment)
102-
}
99+
WorkflowRendering(props.second, environment)
103100
}
104101
}
105102

@@ -110,13 +107,9 @@ class PreviewComposeWorkflowTest {
110107
private val ParentWithTwoChildren =
111108
Workflow.composed<Triple<String, String, String>, Nothing> { props, _, environment ->
112109
Column {
113-
Semantics(container = true) {
114-
WorkflowRendering(rendering = props.first, viewEnvironment = environment)
115-
}
110+
WorkflowRendering(rendering = props.first, viewEnvironment = environment)
116111
Text(props.second)
117-
Semantics(container = true) {
118-
WorkflowRendering(rendering = props.third, viewEnvironment = environment)
119-
}
112+
WorkflowRendering(rendering = props.third, viewEnvironment = environment)
120113
}
121114
}
122115

compose-tooling/src/androidTest/java/com/squareup/workflow/ui/compose/tooling/PreviewViewFactoryTest.kt

+18-27
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import androidx.ui.core.Modifier
2323
import androidx.ui.foundation.Text
2424
import androidx.ui.layout.Column
2525
import androidx.ui.layout.size
26-
import androidx.ui.semantics.Semantics
2726
import androidx.ui.test.assertIsDisplayed
2827
import androidx.ui.test.assertIsNotDisplayed
2928
import androidx.ui.test.createComposeRule
30-
import androidx.ui.test.findByText
29+
import androidx.ui.test.onNodeWithText
3130
import androidx.ui.tooling.preview.Preview
3231
import androidx.ui.unit.dp
3332
import com.squareup.workflow.ui.ViewEnvironmentKey
@@ -47,28 +46,28 @@ class PreviewViewFactoryTest {
4746
ParentWithOneChildPreview()
4847
}
4948

50-
findByText("one").assertIsDisplayed()
51-
findByText("two").assertIsDisplayed()
49+
onNodeWithText("one").assertIsDisplayed()
50+
onNodeWithText("two").assertIsDisplayed()
5251
}
5352

5453
@Test fun twoChildren() {
5554
composeRule.setContent {
5655
ParentWithTwoChildrenPreview()
5756
}
5857

59-
findByText("one").assertIsDisplayed()
60-
findByText("two").assertIsDisplayed()
61-
findByText("three").assertIsDisplayed()
58+
onNodeWithText("one").assertIsDisplayed()
59+
onNodeWithText("two").assertIsDisplayed()
60+
onNodeWithText("three").assertIsDisplayed()
6261
}
6362

6463
@Test fun recursive() {
6564
composeRule.setContent {
6665
ParentRecursivePreview()
6766
}
6867

69-
findByText("one").assertIsDisplayed()
70-
findByText("two").assertIsDisplayed()
71-
findByText("three").assertIsDisplayed()
68+
onNodeWithText("one").assertIsDisplayed()
69+
onNodeWithText("two").assertIsDisplayed()
70+
onNodeWithText("three").assertIsDisplayed()
7271
}
7372

7473
@Test fun modifierIsApplied() {
@@ -77,8 +76,8 @@ class PreviewViewFactoryTest {
7776
}
7877

7978
// The view factory will be rendered with size (0,0), so it should be reported as not displayed.
80-
findByText("one").assertIsNotDisplayed()
81-
findByText("two").assertIsNotDisplayed()
79+
onNodeWithText("one").assertIsNotDisplayed()
80+
onNodeWithText("two").assertIsNotDisplayed()
8281
}
8382

8483
@Test fun placeholderModifierIsApplied() {
@@ -87,25 +86,23 @@ class PreviewViewFactoryTest {
8786
}
8887

8988
// The child will be rendered with size (0,0), so it should be reported as not displayed.
90-
findByText("one").assertIsDisplayed()
91-
findByText("two").assertIsNotDisplayed()
89+
onNodeWithText("one").assertIsDisplayed()
90+
onNodeWithText("two").assertIsNotDisplayed()
9291
}
9392

9493
@Test fun customViewEnvironment() {
9594
composeRule.setContent {
9695
ParentConsumesCustomKeyPreview()
9796
}
9897

99-
findByText("foo").assertIsDisplayed()
98+
onNodeWithText("foo").assertIsDisplayed()
10099
}
101100

102101
private val ParentWithOneChild =
103102
composedViewFactory<Pair<String, String>> { rendering, environment ->
104103
Column {
105104
Text(rendering.first)
106-
Semantics(container = true, mergeAllDescendants = true) {
107-
WorkflowRendering(rendering.second, environment)
108-
}
105+
WorkflowRendering(rendering.second, environment)
109106
}
110107
}
111108

@@ -116,13 +113,9 @@ class PreviewViewFactoryTest {
116113
private val ParentWithTwoChildren =
117114
composedViewFactory<Triple<String, String, String>> { rendering, environment ->
118115
Column {
119-
Semantics(container = true) {
120-
WorkflowRendering(rendering.first, environment)
121-
}
116+
WorkflowRendering(rendering.first, environment)
122117
Text(rendering.second)
123-
Semantics(container = true) {
124-
WorkflowRendering(rendering.third, environment)
125-
}
118+
WorkflowRendering(rendering.third, environment)
126119
}
127120
}
128121

@@ -139,9 +132,7 @@ class PreviewViewFactoryTest {
139132
Column {
140133
Text(rendering.text)
141134
rendering.child?.let { child ->
142-
Semantics(container = true) {
143-
WorkflowRendering(rendering = child, viewEnvironment = environment)
144-
}
135+
WorkflowRendering(rendering = child, viewEnvironment = environment)
145136
}
146137
}
147138
}

compose-tooling/src/main/java/com/squareup/workflow/ui/compose/tooling/PlaceholderViewFactory.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import androidx.ui.graphics.Color
3030
import androidx.ui.graphics.Paint
3131
import androidx.ui.graphics.Shadow
3232
import androidx.ui.graphics.drawscope.DrawScope
33-
import androidx.ui.graphics.drawscope.Stroke
3433
import androidx.ui.graphics.drawscope.drawCanvas
3534
import androidx.ui.graphics.drawscope.rotate
3635
import androidx.ui.graphics.withSaveLayer
@@ -112,10 +111,9 @@ private fun DrawScope.drawHatch(
112111
spaceWidth: Dp,
113112
angle: Float
114113
) {
115-
val strokeWidthPx = strokeWidth.toPx().value
116-
val spaceWidthPx = spaceWidth.toPx().value
114+
val strokeWidthPx = strokeWidth.toPx()
115+
val spaceWidthPx = spaceWidth.toPx()
117116
val strokeColor = color.scaleColors(.5f)
118-
val stroke = Stroke(width = strokeWidthPx)
119117

120118
rotate(angle) {
121119
// Draw outside our bounds to fill the space even when rotated.
@@ -130,7 +128,7 @@ private fun DrawScope.drawHatch(
130128
strokeColor,
131129
Offset(left, y),
132130
Offset(right, y),
133-
stroke = stroke
131+
strokeWidthPx
134132
)
135133
y += spaceWidthPx * 2
136134
}

0 commit comments

Comments
 (0)