Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Upgrade Compose to dev11. #26

Merged
merged 1 commit into from
May 18, 2020
Merged
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.Locale.US
import kotlin.reflect.full.declaredMembers

object Versions {
const val compose = "0.1.0-dev10"
const val compose = "0.1.0-dev11"
const val kotlin = "1.3.71"
const val targetSdk = 29
const val workflow = "0.28.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import androidx.ui.geometry.Offset
import androidx.ui.graphics.Color
import androidx.ui.graphics.Paint
import androidx.ui.graphics.Shadow
import androidx.ui.graphics.withSave
import androidx.ui.graphics.painter.Stroke
import androidx.ui.graphics.painter.drawCanvas
import androidx.ui.graphics.painter.rotate
import androidx.ui.graphics.withSaveLayer
import androidx.ui.layout.fillMaxSize
import androidx.ui.text.TextStyle
Expand All @@ -49,17 +51,19 @@ import com.squareup.workflow.ui.compose.bindCompose
internal fun placeholderViewFactory(modifier: Modifier): ViewFactory<Any> =
bindCompose { rendering, _ ->
Text(
modifier = modifier/*.fillMaxSize()*/
modifier = modifier
.clipToBounds()
.drawBehind {
withSaveLayer(size.toRect(), Paint().apply { alpha = .2f }) {
drawRect(size.toRect(), Paint().apply { color = Color.Gray })
drawCrossHatch(
color = Color.Red,
strokeWidth = 2.dp,
spaceWidth = 5.dp,
angle = 45f
)
drawCanvas { canvas, size ->
canvas.withSaveLayer(size.toRect(), Paint().apply { alpha = .2f }) {
canvas.drawRect(size.toRect(), Paint().apply { color = Color.Gray })
drawCrossHatch(
color = Color.Red,
strokeWidth = 2.dp,
spaceWidth = 5.dp,
angle = 45f
)
}
}
},
text = rendering.toString(),
Expand All @@ -74,25 +78,25 @@ internal fun placeholderViewFactory(modifier: Modifier): ViewFactory<Any> =
@Preview(widthDp = 200, heightDp = 200)
@Composable private fun PreviewStubViewBindingOnWhite() {
Box(backgroundColor = Color.White) {
placeholderViewFactory(Modifier).preview(
rendering = "preview",
modifier = Modifier.fillMaxSize()
.drawBorder(size = 1.dp, color = Color.Red)
)
PreviewStubBindingPreviewTemplate()
}
}

@Preview(widthDp = 200, heightDp = 200)
@Composable private fun PreviewStubViewBindingOnBlack() {
Box(backgroundColor = Color.Black) {
placeholderViewFactory(Modifier).preview(
rendering = "preview",
modifier = Modifier.fillMaxSize()
.drawBorder(size = 1.dp, color = Color.Red)
)
PreviewStubBindingPreviewTemplate()
}
}

@Composable private fun PreviewStubBindingPreviewTemplate() {
placeholderViewFactory(Modifier).preview(
rendering = "preview",
placeholderModifier = Modifier.fillMaxSize()
.drawBorder(size = 1.dp, color = Color.Red)
)
}

private fun DrawScope.drawCrossHatch(
color: Color,
strokeWidth: Dp,
Expand All @@ -109,34 +113,27 @@ private fun DrawScope.drawHatch(
spaceWidth: Dp,
angle: Float
) {
val strokeWidthPx = strokeWidth.toPx()
.value
val paint = Paint().also {
it.color = color.scaleColors(.5f)
it.strokeWidth = strokeWidthPx
}

withSave {
val halfWidth = size.width.value / 2
val halfHeight = size.height.value / 2
translate(halfWidth, halfHeight)
rotate(angle)
translate(-halfWidth, -halfHeight)
val strokeWidthPx = strokeWidth.toPx().value
val spaceWidthPx = spaceWidth.toPx().value
val strokeColor = color.scaleColors(.5f)
val stroke = Stroke(width = strokeWidthPx)

rotate(angle) {
// Draw outside our bounds to fill the space even when rotated.
val left = -size.width.value
val right = size.width.value * 2
val top = -size.height.value
val bottom = size.height.value * 2
val left = -size.width
val right = size.width * 2
val top = -size.height
val bottom = size.height * 2

var y = top + strokeWidthPx * 2f
while (y < bottom) {
drawLine(
strokeColor,
Offset(left, y),
Offset(right, y),
paint
stroke = stroke
)
y += spaceWidth.toPx().value * 2
y += spaceWidthPx * 2
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package com.squareup.sample.nestedrenderings

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.ui.test.SemanticsNodeInteraction
import androidx.ui.test.SemanticsNodeInteractionCollection
import androidx.ui.test.android.AndroidComposeTestRule
import androidx.ui.test.assertCountEquals
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.doClick
import androidx.ui.test.findAllByText
import androidx.ui.test.findByText
import com.google.common.truth.Truth.assertThat
import androidx.ui.test.last
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -35,24 +38,26 @@ class NestedRenderingsTest {
@Rule @JvmField val composeRule = AndroidComposeTestRule<NestedRenderingsActivity>()

@Test fun childrenAreAddedAndRemoved() {
val resetButton = findByText("Reset")

findByText(ADD_BUTTON_TEXT)
.assertIsDisplayed()
.doClick()

findAllByText(ADD_BUTTON_TEXT)
.also { addButtons ->
assertThat(addButtons).hasSize(2)
addButtons.forEach { it.doClick() }
}
.assertCountEquals(2)
.forEach { it.doClick() }

findAllByText(ADD_BUTTON_TEXT)
.also { addButtons ->
assertThat(addButtons).hasSize(4)
}
.assertCountEquals(4)

findAllByText("Reset").last()
.doClick()
findAllByText(ADD_BUTTON_TEXT).assertCountEquals(1)
}

resetButton.doClick()
assertThat(findAllByText(ADD_BUTTON_TEXT)).hasSize(1)
private fun SemanticsNodeInteractionCollection.forEach(
block: (SemanticsNodeInteraction) -> Unit
) {
val count = fetchSemanticsNodes().size
for (i in 0 until count) block(get(i))
}
}

This file was deleted.