From 8d313e6aeb3648a571b7be60592e56330457bef6 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Tue, 9 Jun 2020 17:17:59 +0000 Subject: [PATCH 01/10] Setup snapshot branch --- .github/workflows/build.yml | 3 ++- .github/workflows/release-management.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0a9852ed..b2d2f9f92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - snapshot paths-ignore: - '**.md' pull_request: @@ -100,7 +101,7 @@ jobs: path: junit deploy: - if: github.ref == 'refs/heads/master' + if: github.event_name == 'push' # only deploy for pushed commits (not PRs) runs-on: ubuntu-latest needs: [build, test] env: diff --git a/.github/workflows/release-management.yml b/.github/workflows/release-management.yml index f4be55a13..1efb2c012 100644 --- a/.github/workflows/release-management.yml +++ b/.github/workflows/release-management.yml @@ -4,12 +4,13 @@ on: push: branches: - master + - snapshot jobs: update_draft_release: runs-on: ubuntu-latest steps: # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: toolmantim/release-drafter@v5 + - uses: release-drafter/release-drafter@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b632bdfffe814b04d279b8bea3c2c3a7f38da224 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 10 Jun 2020 07:50:40 +0000 Subject: [PATCH 02/10] Upgrade to AndroidX SNAPSHOT 6572081 --- build.gradle | 10 ++++++++-- .../chrisbanes/accompanist/buildsrc/dependencies.kt | 12 ++++++++---- coil/build.gradle | 6 +++--- .../dev/chrisbanes/accompanist/coil/Crossfade.kt | 4 ++-- mdc-theme/build.gradle | 8 +++++--- sample/build.gradle | 4 ++-- .../accompanist/sample/coil/CoilSampleActivity.kt | 4 +++- .../accompanist/sample/mdc/MdcSampleActivity.kt | 2 +- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 912e015d4..c4fc6dc98 100644 --- a/build.gradle +++ b/build.gradle @@ -38,8 +38,14 @@ plugins { subprojects { repositories { google() - // maven { url 'https://androidx.dev/snapshots/builds/6492492/artifacts/ui/repository' } + mavenCentral() jcenter() + + if (Libs.AndroidX.UI.version.endsWith("SNAPSHOT")) { + maven { + url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.UI.snapshot}/artifacts/ui/repository/" + } + } } apply plugin: 'com.diffplug.gradle.spotless' @@ -93,7 +99,7 @@ subprojects { localProperties.each { prop -> if (prop.key == "signing.secretKeyRingFile") { // If this is the key ring, treat it as a relative path - project.ext.set(prop.key, this.rootProject.file(prop.value).absolutePath) + project.ext.set(prop.key, rootProject.file(prop.value).absolutePath) } else { project.ext.set(prop.key, prop.value) } diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index f3671d3e9..819e383c9 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,10 +51,8 @@ object Libs { } object UI { - const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424" - const val version = "0.1.0-dev12" - - const val composeRuntime = "androidx.compose:compose-runtime:$version" + const val snapshot = "6572081" + const val version = "0.1.0-SNAPSHOT" const val core = "androidx.ui:ui-core:$version" const val foundation = "androidx.ui:ui-foundation:$version" @@ -69,6 +67,12 @@ object Libs { const val test = "androidx.ui:ui-test:$version" } + object Compose { + const val version = UI.version + const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424" + const val runtime = "androidx.compose:compose-runtime:$version" + } + const val core = "androidx.core:core:1.2.0" const val coreKtx = "androidx.core:core-ktx:1.2.0" } diff --git a/coil/build.gradle b/coil/build.gradle index dfdee20f8..9218909cc 100644 --- a/coil/build.gradle +++ b/coil/build.gradle @@ -39,8 +39,8 @@ android { } composeOptions { - kotlinCompilerVersion Libs.AndroidX.UI.kotlinCompilerVersion - kotlinCompilerExtensionVersion Libs.AndroidX.UI.version + kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion + kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version } lintOptions { @@ -74,7 +74,7 @@ dependencies { api Libs.coil implementation Libs.AndroidX.coreKtx - implementation Libs.AndroidX.UI.composeRuntime + implementation Libs.AndroidX.Compose.runtime implementation Libs.AndroidX.UI.foundation implementation Libs.Kotlin.stdlib diff --git a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt index e68874169..5a294116b 100644 --- a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt +++ b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt @@ -172,7 +172,7 @@ private class ObservableCrossfadeImagePainter( private val image: ImageAsset, duration: Int, clock: AnimationClockObservable, - private val srcOffset: Offset = Offset.zero, + private val srcOffset: Offset = Offset.Zero, private val srcSize: Size = Size(image.width.toFloat(), image.height.toFloat()) ) : Painter() { var isFinished by mutableStateOf(false) @@ -207,7 +207,7 @@ private class ObservableCrossfadeImagePainter( paint.asFrameworkPaint().colorFilter = ColorMatrixColorFilter(matrix) drawCanvas { canvas, _ -> - canvas.drawImageRect(image, srcOffset, srcSize, Offset.zero, size, paint) + canvas.drawImageRect(image, srcOffset, srcSize, Offset.Zero, size, paint) } // Reset the Paint instance and release it back to the pool diff --git a/mdc-theme/build.gradle b/mdc-theme/build.gradle index 4a3220901..11b0f6cbf 100644 --- a/mdc-theme/build.gradle +++ b/mdc-theme/build.gradle @@ -39,8 +39,8 @@ android { } composeOptions { - kotlinCompilerVersion Libs.AndroidX.UI.kotlinCompilerVersion - kotlinCompilerExtensionVersion Libs.AndroidX.UI.version + kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion + kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version } lintOptions { @@ -67,9 +67,11 @@ android { dependencies { implementation Libs.AndroidX.coreKtx - implementation Libs.AndroidX.UI.composeRuntime + implementation Libs.AndroidX.Compose.runtime implementation Libs.AndroidX.UI.material + implementation Libs.mdc + implementation Libs.Kotlin.stdlib androidTestImplementation Libs.junit diff --git a/sample/build.gradle b/sample/build.gradle index b88f6c0d4..506b363e4 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -45,7 +45,7 @@ android { } composeOptions { - kotlinCompilerVersion Libs.AndroidX.UI.kotlinCompilerVersion + kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion kotlinCompilerExtensionVersion Libs.AndroidX.UI.version } } @@ -54,7 +54,7 @@ dependencies { implementation project(':mdc-theme') implementation project(':coil') - implementation Libs.AndroidX.UI.composeRuntime + implementation Libs.AndroidX.Compose.runtime implementation Libs.AndroidX.UI.material implementation Libs.AndroidX.UI.foundation implementation Libs.AndroidX.UI.layout diff --git a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilSampleActivity.kt b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilSampleActivity.kt index 5592d99d2..a4a7d9086 100644 --- a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilSampleActivity.kt +++ b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilSampleActivity.kt @@ -27,6 +27,7 @@ import androidx.ui.core.Modifier import androidx.ui.core.setContent import androidx.ui.foundation.Text import androidx.ui.foundation.VerticalScroller +import androidx.ui.layout.ExperimentalLayout import androidx.ui.layout.FlowRow import androidx.ui.layout.Stack import androidx.ui.layout.fillMaxSize @@ -59,10 +60,11 @@ class CoilSampleActivity : AppCompatActivity() { } } +@OptIn(ExperimentalLayout::class) @Composable fun CoilSample() { Scaffold( - topAppBar = { + topBar = { TopAppBar( title = { Text(text = stringResource(R.string.coil_title)) } ) diff --git a/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt b/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt index 15502c39b..b2798e759 100644 --- a/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt +++ b/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt @@ -64,7 +64,7 @@ class MdcSampleActivity : AppCompatActivity() { @Composable fun MdcSample() { Scaffold( - topAppBar = { + topBar = { TopAppBar( title = { Text(text = stringResource(R.string.mdc_title)) } ) From 6fe345439a048b10291cf2c4d7562a7ad9471a47 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 10 Jun 2020 12:50:30 +0100 Subject: [PATCH 03/10] Update to Compose SNAPSHOT 6574163 (#22) * Update to ui SNAPSHOT 6574163 * Fix tests * Fix sample crashing by using AppCompat alpha --- .../accompanist/buildsrc/dependencies.kt | 4 +- .../chrisbanes/accompanist/coil/Assertions.kt | 6 +- .../chrisbanes/accompanist/coil/CoilTest.kt | 69 ++++++++----------- .../dev/chrisbanes/accompanist/coil/Coil.kt | 16 +++-- gradle.properties | 2 +- .../accompanist/mdctheme/MaterialThemeTest.kt | 12 ++-- sample/build.gradle | 2 + 7 files changed, 54 insertions(+), 57 deletions(-) diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index 819e383c9..c2063a4ec 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,7 +51,7 @@ object Libs { } object UI { - const val snapshot = "6572081" + const val snapshot = "6574163" const val version = "0.1.0-SNAPSHOT" const val core = "androidx.ui:ui-core:$version" @@ -75,6 +75,8 @@ object Libs { const val core = "androidx.core:core:1.2.0" const val coreKtx = "androidx.core:core-ktx:1.2.0" + + const val appcompat = "androidx.appcompat:appcompat:1.3.0-alpha01" } const val coil = "io.coil-kt:coil:0.10.1" diff --git a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/Assertions.kt b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/Assertions.kt index 8ec8c9ced..5eced4094 100644 --- a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/Assertions.kt +++ b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/Assertions.kt @@ -19,14 +19,14 @@ package dev.chrisbanes.accompanist.coil import androidx.ui.test.SemanticsNodeInteraction import androidx.ui.unit.Density import androidx.ui.unit.Dp -import androidx.ui.unit.IntPxSize +import androidx.ui.unit.IntSize import org.junit.Assert fun SemanticsNodeInteraction.assertSize(density: Density, width: Dp, height: Dp) { - assertSize(with(density) { IntPxSize(width.toIntPx(), height.toIntPx()) }) + assertSize(with(density) { IntSize(width.toIntPx(), height.toIntPx()) }) } -fun SemanticsNodeInteraction.assertSize(expected: IntPxSize) { +fun SemanticsNodeInteraction.assertSize(expected: IntSize) { val node = fetchSemanticsNode("Assert size") Assert.assertEquals(expected, node.size) } diff --git a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt index c43b48e82..cd26ced71 100644 --- a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt +++ b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt @@ -22,10 +22,9 @@ import androidx.annotation.RawRes import androidx.compose.Composable import androidx.core.net.toUri import androidx.test.filters.LargeTest -import androidx.test.filters.SdkSuppress import androidx.ui.core.ContextAmbient import androidx.ui.core.Modifier -import androidx.ui.core.TestTag +import androidx.ui.core.testTag import androidx.ui.foundation.Text import androidx.ui.graphics.Color import androidx.ui.graphics.painter.ColorPainter @@ -88,13 +87,11 @@ class CoilTest { val latch = CountDownLatch(1) composeTestRule.setContent { - TestTag(CoilTestTags.Image) { - CoilImage( - data = rawUri(R.raw.sample), - modifier = Modifier.preferredSize(128.dp, 128.dp), - onRequestCompleted = { latch.countDown() } - ) - } + CoilImage( + data = rawUri(R.raw.sample), + modifier = Modifier.preferredSize(128.dp, 128.dp).testTag(CoilTestTags.Image), + onRequestCompleted = { latch.countDown() } + ) } // Wait for the onRequestCompleted to release the latch @@ -106,22 +103,19 @@ class CoilTest { } @Test - @SdkSuppress(minSdkVersion = 26) // captureToBitmap is SDK 26+ fun customGetPainter() { val latch = CountDownLatch(1) composeTestRule.setContent { - TestTag(CoilTestTags.Image) { - CoilImage( - data = rawUri(R.raw.sample), - getSuccessPainter = { - // Return a custom success painter which just draws cyan - ColorPainter(Color.Cyan) - }, - modifier = Modifier.preferredSize(128.dp, 128.dp), - onRequestCompleted = { latch.countDown() } - ) - } + CoilImage( + data = rawUri(R.raw.sample), + getSuccessPainter = { + // Return a custom success painter which just draws cyan + ColorPainter(Color.Cyan) + }, + modifier = Modifier.preferredSize(128.dp, 128.dp).testTag(CoilTestTags.Image), + onRequestCompleted = { latch.countDown() } + ) } // Wait for the onRequestCompleted to release the latch @@ -139,13 +133,11 @@ class CoilTest { val latch = CountDownLatch(1) composeTestRule.setContent { - TestTag(CoilTestTags.Image) { - CoilImage( - data = "url_which_will_never_work", - modifier = Modifier.preferredSize(128.dp, 128.dp), - onRequestCompleted = { latch.countDown() } - ) - } + CoilImage( + data = "url_which_will_never_work", + modifier = Modifier.preferredSize(128.dp, 128.dp).testTag(CoilTestTags.Image), + onRequestCompleted = { latch.countDown() } + ) } // Wait for the onRequestCompleted to release the latch @@ -194,22 +186,19 @@ class CoilTest { } @Test - @SdkSuppress(minSdkVersion = 26) // captureToBitmap is SDK 26+ fun customFailurePainter() { val latch = CountDownLatch(1) composeTestRule.setContent { - TestTag(CoilTestTags.Image) { - CoilImage( - data = "url_which_will_never_work", - getFailurePainter = { - // Return a custom failure painter which just draws red - ColorPainter(Color.Red) - }, - modifier = Modifier.preferredSize(128.dp, 128.dp), - onRequestCompleted = { latch.countDown() } - ) - } + CoilImage( + data = "url_which_will_never_work", + getFailurePainter = { + // Return a custom failure painter which just draws red + ColorPainter(Color.Red) + }, + modifier = Modifier.preferredSize(128.dp, 128.dp).testTag(CoilTestTags.Image), + onRequestCompleted = { latch.countDown() } + ) } // Wait for the onRequestCompleted to release the latch diff --git a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt index 77b6e7d1e..4db6921ca 100644 --- a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt +++ b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt @@ -30,8 +30,6 @@ import androidx.ui.core.ContentScale import androidx.ui.core.ContextAmbient import androidx.ui.core.Modifier import androidx.ui.core.WithConstraints -import androidx.ui.core.hasBoundedHeight -import androidx.ui.core.hasBoundedWidth import androidx.ui.core.hasFixedHeight import androidx.ui.core.hasFixedWidth import androidx.ui.foundation.Box @@ -41,6 +39,7 @@ import androidx.ui.graphics.ImageAsset import androidx.ui.graphics.asImageAsset import androidx.ui.graphics.painter.ImagePainter import androidx.ui.graphics.painter.Painter +import androidx.ui.layout.fillMaxSize import coil.Coil import coil.decode.DataSource import coil.request.GetRequest @@ -136,8 +135,8 @@ fun CoilImage( onRequestCompleted: (RequestResult) -> Unit = emptySuccessLambda ) { WithConstraints(modifier) { - val requestWidth = constraints.requestWidth.value - val requestHeight = constraints.requestHeight.value + val requestWidth = constraints.requestWidth + val requestHeight = constraints.requestHeight // Execute the request using executeAsComposable(), which guards the actual execution // so that the request is only run if the request changes. @@ -184,14 +183,19 @@ fun CoilImage( } if (result == null && loading != null) { - Box(modifier, children = loading) + Box( + // We use fillMaxSize() because the WithConstraints handles the incoming modifier + modifier = Modifier.fillMaxSize(), + children = loading + ) } else if (painter != null) { Image( painter = painter, contentScale = contentScale, alignment = alignment, colorFilter = colorFilter, - modifier = modifier + // We use fillMaxSize() because the WithConstraints handles the incoming modifier + modifier = Modifier.fillMaxSize() ) } } diff --git a/gradle.properties b/gradle.properties index c10bd647b..d70a1c460 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.5-SNAPSHOT +VERSION_NAME=0.1.5.ui-6574163-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose diff --git a/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt index d0335f723..4837b8c54 100644 --- a/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt +++ b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt @@ -21,6 +21,7 @@ import androidx.ui.core.DensityAmbient import androidx.ui.foundation.shape.corner.CornerSize import androidx.ui.foundation.shape.corner.CutCornerShape import androidx.ui.foundation.shape.corner.RoundedCornerShape +import androidx.ui.geometry.Size import androidx.ui.material.MaterialTheme import androidx.ui.res.colorResource import androidx.ui.test.android.AndroidComposeTestRule @@ -28,7 +29,6 @@ import androidx.ui.text.font.asFontFamily import androidx.ui.text.font.font import androidx.ui.unit.Density import androidx.ui.unit.Dp -import androidx.ui.unit.PxSize import androidx.ui.unit.TextUnit import androidx.ui.unit.dp import androidx.ui.unit.em @@ -122,8 +122,8 @@ class MaterialThemeTest { assertNotNull(typography.h2.shadow) typography.h2.shadow!!.run { assertEquals(colorResource(R.color.OliveDrab), color) - assertEquals(4.43f, offset.dx) - assertEquals(8.19f, offset.dy) + assertEquals(4.43f, offset.x) + assertEquals(8.19f, offset.y) assertEquals(2.13f, blurRadius) } @@ -143,7 +143,7 @@ class MaterialThemeTest { private fun Dp.scaleToPx(density: Density): Float { val dp = this - return with(density) { dp.toPx().value } + return with(density) { dp.toPx() } } private fun assertTextUnitEquals(expected: TextUnit, actual: TextUnit, density: Density) { @@ -154,8 +154,8 @@ private fun assertTextUnitEquals(expected: TextUnit, actual: TextUnit, density: } else { // Otherwise we need to flatten to a px to compare the values. Again using a // delta to account for float inaccuracy - with(density) { assertEquals(expected.toPx().value, actual.toPx().value, 0.001f) } + with(density) { assertEquals(expected.toPx(), actual.toPx(), 0.001f) } } } -private fun CornerSize.toPx(density: Density) = toPx(PxSize.Companion.UnspecifiedSize, density) +private fun CornerSize.toPx(density: Density) = toPx(Size.UnspecifiedSize, density) diff --git a/sample/build.gradle b/sample/build.gradle index 506b363e4..1cac42c1e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -60,6 +60,8 @@ dependencies { implementation Libs.AndroidX.UI.layout implementation Libs.AndroidX.coreKtx + implementation Libs.AndroidX.appcompat + implementation Libs.mdc implementation Libs.Kotlin.stdlib } From 8033e132f5d4705894c65f4a4ebca5f67f46d0e3 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Fri, 12 Jun 2020 13:12:52 +0100 Subject: [PATCH 04/10] Update to Compose snapshot #6581424 (#27) --- .../java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt | 2 +- .../java/dev/chrisbanes/accompanist/coil/CoilTest.kt | 3 +++ gradle.properties | 2 +- mdc-theme/build.gradle | 2 ++ sample/build.gradle | 1 - 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index 08b432421..e2282c94b 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,7 +51,7 @@ object Libs { } object UI { - const val snapshot = "6574163" + const val snapshot = "6581424" const val version = "0.1.0-SNAPSHOT" const val core = "androidx.ui:ui-core:$version" diff --git a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt index f1f0943a9..b3067da6b 100644 --- a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt +++ b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt @@ -22,6 +22,7 @@ import androidx.annotation.RawRes import androidx.compose.Composable import androidx.core.net.toUri import androidx.test.filters.LargeTest +import androidx.test.filters.SdkSuppress import androidx.ui.core.ContextAmbient import androidx.ui.core.Modifier import androidx.ui.core.testTag @@ -103,6 +104,7 @@ class CoilTest { } @Test + @SdkSuppress(minSdkVersion = 26) // captureToBitmap is SDK 26+ fun customGetPainter() { val latch = CountDownLatch(1) @@ -186,6 +188,7 @@ class CoilTest { } @Test + @SdkSuppress(minSdkVersion = 26) // captureToBitmap is SDK 26+ fun customFailurePainter() { val latch = CountDownLatch(1) diff --git a/gradle.properties b/gradle.properties index 1f68aea40..ca01f0eea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.6.ui-6574163-SNAPSHOT +VERSION_NAME=0.1.6.ui-6581424-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose diff --git a/mdc-theme/build.gradle b/mdc-theme/build.gradle index 11b0f6cbf..7c546c306 100644 --- a/mdc-theme/build.gradle +++ b/mdc-theme/build.gradle @@ -71,6 +71,8 @@ dependencies { implementation Libs.AndroidX.UI.material implementation Libs.mdc + // We need to force AppCompat v1.3.0-alpha01 for AppCompatActivity to work with Compose + implementation Libs.AndroidX.appcompat implementation Libs.Kotlin.stdlib diff --git a/sample/build.gradle b/sample/build.gradle index 1cac42c1e..9481be505 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -60,7 +60,6 @@ dependencies { implementation Libs.AndroidX.UI.layout implementation Libs.AndroidX.coreKtx - implementation Libs.AndroidX.appcompat implementation Libs.mdc implementation Libs.Kotlin.stdlib From 679a456f1fc5e2aaee63f471b84080249aa3658c Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Mon, 15 Jun 2020 12:16:47 +0000 Subject: [PATCH 05/10] Try out Compose/UI Snapshot 6589751 --- .../java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index e2282c94b..1b74705a0 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,7 +51,7 @@ object Libs { } object UI { - const val snapshot = "6581424" + const val snapshot = "6589751" const val version = "0.1.0-SNAPSHOT" const val core = "androidx.ui:ui-core:$version" diff --git a/gradle.properties b/gradle.properties index ca01f0eea..86ae0ceed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.6.ui-6581424-SNAPSHOT +VERSION_NAME=0.1.6.ui-6589751-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose From 509f49a37278a0b168311c2e19aede94345f60ff Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Thu, 18 Jun 2020 15:52:05 +0000 Subject: [PATCH 06/10] Update to SNAPSHOT #6602655 --- .../chrisbanes/accompanist/buildsrc/dependencies.kt | 2 +- .../dev/chrisbanes/accompanist/coil/Crossfade.kt | 12 +++++++----- gradle.properties | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index 64743b7d2..e46c02f09 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,7 +51,7 @@ object Libs { } object UI { - const val snapshot = "6589751" + const val snapshot = "6602655" const val version = "0.1.0-SNAPSHOT" const val core = "androidx.ui:ui-core:$version" diff --git a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt index 5a294116b..d353977ff 100644 --- a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt +++ b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt @@ -34,13 +34,15 @@ import androidx.ui.core.AnimationClockAmbient import androidx.ui.core.ContentScale import androidx.ui.core.Modifier import androidx.ui.foundation.Image -import androidx.ui.geometry.Offset import androidx.ui.geometry.Size import androidx.ui.graphics.ImageAsset import androidx.ui.graphics.Paint import androidx.ui.graphics.drawscope.DrawScope import androidx.ui.graphics.drawscope.drawCanvas import androidx.ui.graphics.painter.Painter +import androidx.ui.unit.IntOffset +import androidx.ui.unit.IntSize +import androidx.ui.unit.toSize import coil.Coil import coil.decode.DataSource import coil.request.GetRequest @@ -172,8 +174,8 @@ private class ObservableCrossfadeImagePainter( private val image: ImageAsset, duration: Int, clock: AnimationClockObservable, - private val srcOffset: Offset = Offset.Zero, - private val srcSize: Size = Size(image.width.toFloat(), image.height.toFloat()) + private val srcOffset: IntOffset = IntOffset.Origin, + private val srcSize: IntSize = IntSize(image.width, image.height) ) : Painter() { var isFinished by mutableStateOf(false) private set @@ -207,7 +209,7 @@ private class ObservableCrossfadeImagePainter( paint.asFrameworkPaint().colorFilter = ColorMatrixColorFilter(matrix) drawCanvas { canvas, _ -> - canvas.drawImageRect(image, srcOffset, srcSize, Offset.Zero, size, paint) + canvas.drawImageRect(image, srcOffset, srcSize, IntOffset.Origin, srcSize, paint) } // Reset the Paint instance and release it back to the pool @@ -218,7 +220,7 @@ private class ObservableCrossfadeImagePainter( /** * Return the dimension of the underlying [Image] as its intrinsic width and height */ - override val intrinsicSize: Size get() = srcSize + override val intrinsicSize: Size get() = srcSize.toSize() fun start() { // Start the animation by transitioning to the Loaded state diff --git a/gradle.properties b/gradle.properties index 86ae0ceed..3d80762cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.6.ui-6589751-SNAPSHOT +VERSION_NAME=0.1.6.ui-6602655-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose From e47b294269ee6ff323d928cc692fc3ca9acbd2ec Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Mon, 22 Jun 2020 18:27:21 +0100 Subject: [PATCH 07/10] Fix isNotMaterialTheme test not running --- .../accompanist/mdctheme/MaterialThemeTest.kt | 10 ----- .../mdctheme/NotMaterialThemeTest.kt | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/NotMaterialThemeTest.kt diff --git a/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt index 14a7f40fa..4837b8c54 100644 --- a/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt +++ b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeTest.kt @@ -49,16 +49,6 @@ class MaterialThemeTest { @get:Rule val composeTestRule = AndroidComposeTestRule() - @get:Rule - val notMdcComposeTestRule = AndroidComposeTestRule() - - @Test(expected = IllegalArgumentException::class) - fun isNotMaterialTheme() = notMdcComposeTestRule.setContent { - MaterialThemeFromMdcTheme { - // Nothing to do here, exception should be thrown - } - } - @Test fun colors() = composeTestRule.setContent { MaterialThemeFromMdcTheme { diff --git a/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/NotMaterialThemeTest.kt b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/NotMaterialThemeTest.kt new file mode 100644 index 000000000..16f20888d --- /dev/null +++ b/mdc-theme/src/androidTest/java/dev/chrisbanes/accompanist/mdctheme/NotMaterialThemeTest.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.chrisbanes.accompanist.mdctheme + +import androidx.test.filters.MediumTest +import androidx.ui.test.android.AndroidComposeTestRule +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@MediumTest +@RunWith(JUnit4::class) +class NotMaterialThemeTest { + @get:Rule + val composeTestRule = AndroidComposeTestRule() + + @Test(expected = IllegalArgumentException::class) + fun isNotMaterialTheme() = composeTestRule.setContent { + MaterialThemeFromMdcTheme { + // Nothing to do here, exception should be thrown + } + } +} From 2457bef4cc9a0b39c4fb260ff3381a3824c9cc47 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Tue, 7 Jul 2020 16:50:04 +0100 Subject: [PATCH 08/10] Update to Compose SNAPSHOT #6658828 Required some changes to generateMaterialThemeFromMdcTheme(). Calling composable functions is no longer allowed within remember {} calls, so I converted generateMaterialThemeFromMdcTheme() to be non-composable. There was no real need for it to be composable, other than convenient access to ambients. --- build.gradle | 4 +- .../accompanist/buildsrc/dependencies.kt | 28 +++++------- coil/build.gradle | 6 +-- .../dev/chrisbanes/accompanist/coil/Coil.kt | 5 ++- .../chrisbanes/accompanist/coil/Crossfade.kt | 26 +++++------ gradle.properties | 2 +- mdc-theme/build.gradle | 6 +-- .../mdctheme/MaterialThemeFromMdcTheme.kt | 45 ++++++++++++------- sample/build.gradle | 8 ++-- 9 files changed, 68 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index fbaf73d9a..28d9c32ab 100644 --- a/build.gradle +++ b/build.gradle @@ -41,9 +41,9 @@ subprojects { mavenCentral() jcenter() - if (Libs.AndroidX.UI.version.endsWith("SNAPSHOT")) { + if (Libs.AndroidX.Compose.version.endsWith("SNAPSHOT")) { maven { - url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.UI.snapshot}/artifacts/ui/repository/" + url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.Compose.snapshot}/artifacts/ui/repository/" } } } diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index 944f6b93d..4e794560e 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -50,27 +50,19 @@ object Libs { const val espressoCore = "androidx.test.espresso:espresso-core:3.2.0" } - object UI { - const val snapshot = "6602655" - const val version = "0.1.0-SNAPSHOT" - - const val core = "androidx.ui:ui-core:$version" - const val foundation = "androidx.ui:ui-foundation:$version" - - const val layout = "androidx.ui:ui-layout:$version" - const val material = "androidx.ui:ui-material:$version" - - const val animation = "androidx.ui:ui-animation:$version" - const val tooling = "androidx.ui:ui-tooling:$version" - const val livedata = "androidx.ui:ui-livedata:$version" - - const val test = "androidx.ui:ui-test:$version" - } - object Compose { - const val version = UI.version + const val snapshot = "6658922" + const val version = "0.1.0-SNAPSHOT" + const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424" + const val runtime = "androidx.compose:compose-runtime:$version" + const val core = "androidx.ui:ui-core:${version}" + const val foundation = "androidx.compose.foundation:foundation:${version}" + const val layout = "androidx.ui:ui-layout:${version}" + const val material = "androidx.compose.material:material:${version}" + const val tooling = "androidx.compose.tooling:tooling:${version}" + const val test = "androidx.compose.test:test-core:${version}" } const val core = "androidx.core:core:1.2.0" diff --git a/coil/build.gradle b/coil/build.gradle index 9218909cc..02c0942ad 100644 --- a/coil/build.gradle +++ b/coil/build.gradle @@ -75,7 +75,7 @@ dependencies { implementation Libs.AndroidX.coreKtx implementation Libs.AndroidX.Compose.runtime - implementation Libs.AndroidX.UI.foundation + implementation Libs.AndroidX.Compose.foundation implementation Libs.Kotlin.stdlib @@ -84,8 +84,8 @@ dependencies { androidTestImplementation Libs.Coroutines.test - androidTestImplementation Libs.AndroidX.UI.test - androidTestImplementation Libs.AndroidX.UI.core + androidTestImplementation Libs.AndroidX.Compose.test + androidTestImplementation Libs.AndroidX.Compose.core androidTestImplementation Libs.AndroidX.Test.rules androidTestImplementation Libs.AndroidX.Test.runner } diff --git a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt index e6d308e9b..fa5fb6aa4 100644 --- a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt +++ b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt @@ -78,8 +78,9 @@ fun CoilImage( // pass the request through is GetRequest -> data // Otherwise we construct a GetRequest using the data parameter - else -> remember(data) { - GetRequest.Builder(ContextAmbient.current).data(data).build() + else -> { + val context = ContextAmbient.current + remember(data) { GetRequest.Builder(context).data(data).build() } } }, alignment = alignment, diff --git a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt index d353977ff..c69457635 100644 --- a/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt +++ b/coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt @@ -21,10 +21,11 @@ import androidx.animation.AnimationClockObservable import androidx.animation.FloatPropKey import androidx.animation.createAnimation import androidx.animation.transitionDefinition +import androidx.animation.tween import androidx.compose.Composable -import androidx.compose.NeverEqual import androidx.compose.getValue import androidx.compose.mutableStateOf +import androidx.compose.neverEqualPolicy import androidx.compose.remember import androidx.compose.setValue import androidx.core.util.Pools @@ -47,7 +48,6 @@ import coil.Coil import coil.decode.DataSource import coil.request.GetRequest import coil.request.GetRequestBuilder -import kotlin.math.roundToInt private const val DefaultTransitionDuration = 1000 @@ -182,7 +182,10 @@ private class ObservableCrossfadeImagePainter( // Initial matrix is completely transparent. We use the NeverEqual equivalence check since this // is a mutable entity. - private var matrix by mutableStateOf(ImageLoadingColorMatrix(0f, 0f, 0f), NeverEqual) + private var matrix by mutableStateOf( + value = ImageLoadingColorMatrix(0f, 0f, 0f), + policy = neverEqualPolicy() + ) private val animation = CrossfadeTransition.definition(duration).createAnimation(clock) @@ -256,17 +259,12 @@ private object CrossfadeTransition { } transition { - Alpha using tween { - // Alpha animation runs over the first 50% - duration = durationMs / 2 - } - Brightness using tween { - // Brightness animation runs over the first 75% - duration = (durationMs * 0.75f).roundToInt() - } - Saturation using tween { - duration = durationMs - } + // Alpha animates over the first 50% + Alpha using tween(durationMillis = durationMs / 2) + // Brightness animates over the first 75% + Brightness using tween(durationMillis = durationMs * 3 / 4) + // Saturation animates over whole duration + Saturation using tween(durationMillis = durationMs) } } } diff --git a/gradle.properties b/gradle.properties index 0f00a4df2..3b74ffbb8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.7.ui-6602655-SNAPSHOT +VERSION_NAME=0.1.7.ui-6658828-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose diff --git a/mdc-theme/build.gradle b/mdc-theme/build.gradle index 7c546c306..331815c9f 100644 --- a/mdc-theme/build.gradle +++ b/mdc-theme/build.gradle @@ -68,7 +68,7 @@ android { dependencies { implementation Libs.AndroidX.coreKtx implementation Libs.AndroidX.Compose.runtime - implementation Libs.AndroidX.UI.material + implementation Libs.AndroidX.Compose.material implementation Libs.mdc // We need to force AppCompat v1.3.0-alpha01 for AppCompatActivity to work with Compose @@ -77,8 +77,8 @@ dependencies { implementation Libs.Kotlin.stdlib androidTestImplementation Libs.junit - androidTestImplementation Libs.AndroidX.UI.test - androidTestImplementation Libs.AndroidX.UI.core + androidTestImplementation Libs.AndroidX.Compose.test + androidTestImplementation Libs.AndroidX.Compose.core androidTestImplementation Libs.AndroidX.Test.rules androidTestImplementation Libs.AndroidX.Test.runner } diff --git a/mdc-theme/src/main/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeFromMdcTheme.kt b/mdc-theme/src/main/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeFromMdcTheme.kt index 89ca1b0a9..551fd8bdf 100644 --- a/mdc-theme/src/main/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeFromMdcTheme.kt +++ b/mdc-theme/src/main/java/dev/chrisbanes/accompanist/mdctheme/MaterialThemeFromMdcTheme.kt @@ -17,6 +17,7 @@ package dev.chrisbanes.accompanist.mdctheme import android.content.Context +import android.content.res.Configuration import android.content.res.Resources import android.content.res.TypedArray import android.graphics.Typeface @@ -29,8 +30,6 @@ import androidx.core.content.res.getColorOrThrow import androidx.core.content.res.getResourceIdOrThrow import androidx.core.content.res.use import androidx.ui.core.ContextAmbient -import androidx.ui.core.DensityAmbient -import androidx.ui.foundation.isSystemInDarkTheme import androidx.ui.foundation.shape.corner.CornerBasedShape import androidx.ui.foundation.shape.corner.CornerSize import androidx.ui.foundation.shape.corner.CutCornerShape @@ -94,11 +93,11 @@ fun MaterialThemeFromMdcTheme( val (colors, type, shapes) = remember(key) { generateMaterialThemeFromMdcTheme( - context, - readColors, - readTypography, - readShapes, - useTextColors + context = context, + readColors = readColors, + readTypography = readTypography, + readShapes = readShapes, + useTextColors = useTextColors ) } @@ -111,7 +110,7 @@ fun MaterialThemeFromMdcTheme( } /** - * This effect generates the components of an [androidx.ui.material.MaterialTheme], reading the + * This effect generates the components of a [androidx.ui.material.MaterialTheme], reading the * values from an Material Design Components Android theme. * * By default the text colors from any associated `TextAppearance`s from the theme are *not* read. @@ -120,15 +119,16 @@ fun MaterialThemeFromMdcTheme( * You can customize this through the [useTextColors] parameter. * * @param context The context to read the theme from + * @param density The current density * @param readColors whether the read the MDC color palette from the context's theme * @param readTypography whether the read the MDC typography text appearances from the context's theme * @param readShapes whether the read the MDC shape appearances from the context's theme * @param useTextColors whether to read the colors from the `TextAppearance`s associated from the * theme. Defaults to `false` */ -@Composable fun generateMaterialThemeFromMdcTheme( - context: Context = ContextAmbient.current, + context: Context, + density: Density = Density(context), readColors: Boolean = true, readTypography: Boolean = true, readShapes: Boolean = true, @@ -189,7 +189,12 @@ fun generateMaterialThemeFromMdcTheme( } } else { // Else we create an empty color palette based on the configuration's uiMode - if (isSystemInDarkTheme()) darkColorPalette() else lightColorPalette() + val uiMode = context.resources.configuration.uiMode + if ((uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) { + darkColorPalette() + } else { + lightColorPalette() + } } /** @@ -205,66 +210,79 @@ fun generateMaterialThemeFromMdcTheme( typography = typography.merge( h1 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline1), useTextColors ), h2 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline2), useTextColors ), h3 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline3), useTextColors ), h4 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline4), useTextColors ), h5 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline5), useTextColors ), h6 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceHeadline6), useTextColors ), subtitle1 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceSubtitle1), useTextColors ), subtitle2 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceSubtitle2), useTextColors ), body1 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceBody1), useTextColors ), body2 = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceBody2), useTextColors ), button = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceButton), useTextColors ), caption = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceCaption), useTextColors ), overline = textStyleFromTextAppearance( context, + density, ta.getResourceIdOrThrow(R.styleable.AccompanistMdcTheme_textAppearanceOverline), useTextColors ) @@ -300,9 +318,9 @@ fun generateMaterialThemeFromMdcTheme( } } -@Composable private fun textStyleFromTextAppearance( context: Context, + density: Density, @StyleRes id: Int, useTextColor: Boolean ): TextStyle { @@ -314,8 +332,6 @@ private fun textStyleFromTextAppearance( // TODO read and expand android:fontVariationSettings. // Variable fonts are not supported in Compose yet - val density = DensityAmbient.current - // FYI, this only works with static font files in assets val fontFamilyWeight = when { a.hasValue(R.styleable.AccompanistMdcTextAppearance_android_fontFamily) -> { @@ -378,7 +394,6 @@ private fun textStyleFromTextAppearance( } } -@Composable private fun readShapeAppearance( context: Context, @StyleRes id: Int, diff --git a/sample/build.gradle b/sample/build.gradle index 9481be505..8fb7d7c0f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -46,7 +46,7 @@ android { composeOptions { kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion - kotlinCompilerExtensionVersion Libs.AndroidX.UI.version + kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version } } @@ -55,9 +55,9 @@ dependencies { implementation project(':coil') implementation Libs.AndroidX.Compose.runtime - implementation Libs.AndroidX.UI.material - implementation Libs.AndroidX.UI.foundation - implementation Libs.AndroidX.UI.layout + implementation Libs.AndroidX.Compose.material + implementation Libs.AndroidX.Compose.foundation + implementation Libs.AndroidX.Compose.layout implementation Libs.AndroidX.coreKtx From f4e47836707d7c89e9332c92c9db7f48a0d830a7 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Thu, 16 Jul 2020 11:13:48 +0100 Subject: [PATCH 09/10] Update to SNAPSHOT: 6695716 --- build.gradle | 22 +++++++--------- .../accompanist/buildsrc/dependencies.kt | 21 ++++++++------- coil/build.gradle | 3 ++- .../chrisbanes/accompanist/coil/CoilTest.kt | 26 +++++++++---------- gradle.properties | 2 +- mdc-theme/build.gradle | 2 +- .../sample/coil/CoilBasicSample.kt | 4 +-- .../accompanist/sample/coil/CoilGridSample.kt | 4 +-- .../sample/mdc/MdcSampleActivity.kt | 4 +-- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/build.gradle b/build.gradle index 28d9c32ab..12a189c89 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ buildscript { repositories { google() jcenter() + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap/' } } dependencies { @@ -41,6 +42,8 @@ subprojects { mavenCentral() jcenter() + maven { url 'https://dl.bintray.com/kotlin/kotlin-eap/' } + if (Libs.AndroidX.Compose.version.endsWith("SNAPSHOT")) { maven { url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.Compose.snapshot}/artifacts/ui/repository/" @@ -53,13 +56,13 @@ subprojects { kotlin { target "**/*.kt" ktlint(Versions.ktlint) - licenseHeaderFile project.rootProject.file('spotless/copyright.txt') + licenseHeaderFile rootProject.file('spotless/copyright.txt') } groovyGradle { target '**/*.gradle' - greclipse().configFile(project.rootProject.file('spotless/greclipse.properties')) - licenseHeaderFile project.rootProject.file('spotless/copyright.txt'), + greclipse().configFile(rootProject.file('spotless/greclipse.properties')) + licenseHeaderFile rootProject.file('spotless/copyright.txt'), '(buildscript|apply|import)' } } @@ -75,16 +78,11 @@ subprojects { // Allow use of @OptIn freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" - // Compose is now based on the Kotlin 1.4 compiler, but we need to use the 1.3.x Kotlin - // library due to library compatibility, etc. Therefore we explicit set our apiVersion - // to 1.3 to fix any warnings. Binary dependencies (such as Compose) can continue to - // use 1.4 if built with that library. - // TODO: remove this once we move to Kotlin 1.4 - apiVersion = "1.3" + freeCompilerArgs += "-Xallow-jvm-ir-dependencies" - // Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit` - // TODO: Remove when we move to Kotlin 1.4 - freeCompilerArgs += "-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes" + // Since we're using a pre-release version of the Kotlin compiler, we need + // to disable it's pre-release check + freeCompilerArgs += "-Xskip-prerelease-check" } } diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index 459e1b08b..e87edee49 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -28,13 +28,13 @@ object Libs { const val junit = "junit:junit:4.13" object Kotlin { - private const val version = "1.3.72" + const val version = "1.4-M3" const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version" const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version" } object Coroutines { - private const val version = "1.3.7" + private const val version = "1.3.7-1.4-M3" const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version" const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$version" } @@ -51,18 +51,19 @@ object Libs { } object Compose { - const val snapshot = "6658922" + const val snapshot = "6695716" const val version = "0.1.0-SNAPSHOT" + const val kotlinCompilerVersion = "1.4.0-dev-withExperimentalGoogleExtensions-20200720" - const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424" - - const val runtime = "androidx.compose:compose-runtime:$version" - const val core = "androidx.ui:ui-core:${version}" + const val runtime = "androidx.compose.runtime:runtime:$version" const val foundation = "androidx.compose.foundation:foundation:${version}" - const val layout = "androidx.ui:ui-layout:${version}" + const val layout = "androidx.compose.foundation:foundation-layout:${version}" + + const val ui = "androidx.compose.ui:ui:${version}" const val material = "androidx.compose.material:material:${version}" - const val tooling = "androidx.compose.tooling:tooling:${version}" - const val test = "androidx.compose.test:test-core:${version}" + + const val tooling = "androidx.ui:ui-tooling:${version}" + const val test = "androidx.ui:ui-test:${version}" } const val core = "androidx.core:core:1.2.0" diff --git a/coil/build.gradle b/coil/build.gradle index 02c0942ad..9932c2725 100644 --- a/coil/build.gradle +++ b/coil/build.gradle @@ -78,6 +78,7 @@ dependencies { implementation Libs.AndroidX.Compose.foundation implementation Libs.Kotlin.stdlib + implementation Libs.Coroutines.android androidTestImplementation Libs.junit androidTestImplementation Libs.truth @@ -85,7 +86,7 @@ dependencies { androidTestImplementation Libs.Coroutines.test androidTestImplementation Libs.AndroidX.Compose.test - androidTestImplementation Libs.AndroidX.Compose.core + androidTestImplementation Libs.AndroidX.Compose.ui androidTestImplementation Libs.AndroidX.Test.rules androidTestImplementation Libs.AndroidX.Test.runner } diff --git a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt index beb3660f9..21786c81d 100644 --- a/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt +++ b/coil/src/androidTest/java/dev/chrisbanes/accompanist/coil/CoilTest.kt @@ -34,9 +34,9 @@ import androidx.ui.test.assertIsDisplayed import androidx.ui.test.assertPixels import androidx.ui.test.captureToBitmap import androidx.ui.test.createComposeRule -import androidx.ui.test.findByTag -import androidx.ui.test.findByText -import androidx.ui.test.runOnIdleCompose +import androidx.ui.test.onNodeWithTag +import androidx.ui.test.onNodeWithText +import androidx.ui.test.runOnIdle import androidx.ui.unit.dp import coil.request.CachePolicy import coil.request.GetRequest @@ -81,7 +81,7 @@ class CoilTest { // Wait for the Coil request listener to release the latch latch.await(5, TimeUnit.SECONDS) - runOnIdleCompose { + runOnIdle { // And assert that we got a single successful result assertThat(results).hasSize(1) assertThat(results[0]).isInstanceOf(SuccessResult::class.java) @@ -103,7 +103,7 @@ class CoilTest { // Wait for the onRequestCompleted to release the latch latch.await(5, TimeUnit.SECONDS) - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertIsDisplayed() .assertSize(composeTestRule.density, 128.dp, 128.dp) } @@ -124,7 +124,7 @@ class CoilTest { // Wait for the onRequestCompleted to release the latch latch.await(5, TimeUnit.SECONDS) - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertSize(composeTestRule.density, 128.dp, 128.dp) .assertIsDisplayed() .captureToBitmap() @@ -153,7 +153,7 @@ class CoilTest { } // Assert that the content is completely Red - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertSize(composeTestRule.density, 128.dp, 128.dp) .assertIsDisplayed() .captureToBitmap() @@ -166,7 +166,7 @@ class CoilTest { runBlocking { loadCompleteSignal.receive() } // Assert that the content is completely Blue - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertSize(composeTestRule.density, 128.dp, 128.dp) .assertIsDisplayed() .captureToBitmap() @@ -230,7 +230,7 @@ class CoilTest { latch.await(5, TimeUnit.SECONDS) // Assert that the whole layout is drawn cyan - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertIsDisplayed() .captureToBitmap() .assertPixels { Color.Cyan } @@ -252,7 +252,7 @@ class CoilTest { latch.await(5, TimeUnit.SECONDS) // Assert that the layout is in the tree and has the correct size - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertIsDisplayed() .assertSize(composeTestRule.density, 128.dp, 128.dp) } @@ -281,7 +281,7 @@ class CoilTest { } // Assert that the loading component is displayed - findByText("Loading").assertIsDisplayed() + onNodeWithText("Loading").assertIsDisplayed() // Now resume the dispatcher to start the Coil request, and wait for the // request to complete @@ -289,7 +289,7 @@ class CoilTest { latch.await(5, TimeUnit.SECONDS) // And assert that the loading component no longer exists - findByText("Loading").assertDoesNotExist() + onNodeWithText("Loading").assertDoesNotExist() } } @@ -314,7 +314,7 @@ class CoilTest { latch.await(5, TimeUnit.SECONDS) // Assert that the whole layout is drawn red - findByTag(CoilTestTags.Image) + onNodeWithTag(CoilTestTags.Image) .assertIsDisplayed() .captureToBitmap() .assertPixels { Color.Red } diff --git a/gradle.properties b/gradle.properties index 3b74ffbb8..2712f52d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.7.ui-6658828-SNAPSHOT +VERSION_NAME=0.1.7.ui-6684705-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose diff --git a/mdc-theme/build.gradle b/mdc-theme/build.gradle index 331815c9f..d8fad6eab 100644 --- a/mdc-theme/build.gradle +++ b/mdc-theme/build.gradle @@ -78,7 +78,7 @@ dependencies { androidTestImplementation Libs.junit androidTestImplementation Libs.AndroidX.Compose.test - androidTestImplementation Libs.AndroidX.Compose.core + androidTestImplementation Libs.AndroidX.Compose.ui androidTestImplementation Libs.AndroidX.Test.rules androidTestImplementation Libs.AndroidX.Test.runner } diff --git a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilBasicSample.kt b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilBasicSample.kt index f1db5bab4..66c87159a 100644 --- a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilBasicSample.kt +++ b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilBasicSample.kt @@ -25,8 +25,8 @@ import androidx.ui.core.Alignment import androidx.ui.core.ContextAmbient import androidx.ui.core.Modifier import androidx.ui.core.setContent +import androidx.ui.foundation.ScrollableColumn import androidx.ui.foundation.Text -import androidx.ui.foundation.VerticalScroller import androidx.ui.layout.ExperimentalLayout import androidx.ui.layout.FlowRow import androidx.ui.layout.Stack @@ -70,7 +70,7 @@ private fun Sample() { ) } ) { - VerticalScroller(modifier = Modifier.padding(16.dp)) { + ScrollableColumn(modifier = Modifier.padding(16.dp)) { FlowRow( mainAxisSpacing = 4.dp, crossAxisSpacing = 4.dp diff --git a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilGridSample.kt b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilGridSample.kt index e2f8ec8c8..e8ee9950b 100644 --- a/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilGridSample.kt +++ b/sample/src/main/java/dev/chrisbanes/accompanist/sample/coil/CoilGridSample.kt @@ -23,8 +23,8 @@ import androidx.compose.Composable import androidx.compose.Recomposer import androidx.ui.core.Modifier import androidx.ui.core.setContent +import androidx.ui.foundation.ScrollableColumn import androidx.ui.foundation.Text -import androidx.ui.foundation.VerticalScroller import androidx.ui.layout.ExperimentalLayout import androidx.ui.layout.FlowRow import androidx.ui.layout.padding @@ -64,7 +64,7 @@ private fun Sample() { ) } ) { - VerticalScroller(modifier = Modifier.padding(16.dp)) { + ScrollableColumn(modifier = Modifier.padding(16.dp)) { FlowRow( mainAxisSpacing = 4.dp, crossAxisSpacing = 4.dp diff --git a/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt b/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt index b2798e759..df26c7036 100644 --- a/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt +++ b/sample/src/main/java/dev/chrisbanes/accompanist/sample/mdc/MdcSampleActivity.kt @@ -24,8 +24,8 @@ import androidx.compose.Recomposer import androidx.ui.core.Modifier import androidx.ui.core.setContent import androidx.ui.foundation.Icon +import androidx.ui.foundation.ScrollableColumn import androidx.ui.foundation.Text -import androidx.ui.foundation.VerticalScroller import androidx.ui.layout.Column import androidx.ui.layout.Spacer import androidx.ui.layout.padding @@ -70,7 +70,7 @@ fun MdcSample() { ) } ) { - VerticalScroller { + ScrollableColumn { Column(Modifier.padding(16.dp)) { CircularProgressIndicator() Spacer(modifier = Modifier.preferredHeight(8.dp)) From efe959d024e3becf1e81a607e29f815df7359e4d Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 22 Jul 2020 19:42:29 +0100 Subject: [PATCH 10/10] Update to Compose v0.1.0-dev15 --- .../java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt index e87edee49..48ff8d1f0 100644 --- a/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt +++ b/buildSrc/src/main/java/dev/chrisbanes/accompanist/buildsrc/dependencies.kt @@ -51,8 +51,8 @@ object Libs { } object Compose { - const val snapshot = "6695716" - const val version = "0.1.0-SNAPSHOT" + const val snapshot = "" + const val version = "0.1.0-dev15" const val kotlinCompilerVersion = "1.4.0-dev-withExperimentalGoogleExtensions-20200720" const val runtime = "androidx.compose.runtime:runtime:$version" diff --git a/gradle.properties b/gradle.properties index 2712f52d4..eb737470f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ android.enableJetifier=true systemProp.org.gradle.internal.publish.checksums.insecure=true GROUP=dev.chrisbanes.accompanist -VERSION_NAME=0.1.7.ui-6684705-SNAPSHOT +VERSION_NAME=0.1.7-SNAPSHOT POM_DESCRIPTION=A collection of utilities for Jetpack Compose