Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 5f208c3

Browse files
authored
Update to Compose dev16 (#8)
* Update to Compose dev16 * Update AGP to 4.2.0-alpha07 * compileSdk is now 30 * Fix MdcThemeTest when running in system dark theme * Update Spotless to 5.1.1 * Update README
1 parent 2c85390 commit 5f208c3

File tree

14 files changed

+244
-117
lines changed

14 files changed

+244
-117
lines changed

.idea/codeStyles/Project.xml

Lines changed: 117 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A library that enables reuse of [Material Components for Android][mdc] XML themes for theming in [Jetpack Compose][compose].
44

5-
The basis of theming in Jetpack Compose is the [`MaterialTheme`][materialtheme] composable, where you provide [`ColorPalette`](https://developer.android.com/reference/kotlin/androidx/ui/material/ColorPalette), [`Shapes`](https://developer.android.com/reference/kotlin/androidx/ui/material/Shapes) and [`Typography`](https://developer.android.com/reference/kotlin/androidx/ui/material/Typography) instances containing your styling parameters:
5+
The basis of theming in [Jetpack Compose][compose] is the [`MaterialTheme`][materialtheme] composable, where you provide [`Colors`][colors], [`Shapes`][shapes] and [`Typography`][typography] instances containing your styling parameters:
66

77
``` kotlin
88
MaterialTheme(
@@ -31,7 +31,7 @@ MaterialTheme(
3131
</style>
3232
```
3333

34-
This library attempts to bridge the gap between [Material Components for Android][mdc] XML themes, and themes in [Jetpack Compose][compose], allowing your composable `MaterialTheme` to be based on the `Activity`'s XML theme:
34+
This library attempts to bridge the gap between [Material Components for Android][mdc] XML themes, and themes in [Jetpack Compose][compose], allowing your composable [`MaterialTheme`][materialtheme] to be based on the `Activity`'s XML theme:
3535

3636

3737
``` kotlin
@@ -120,5 +120,7 @@ limitations under the License.
120120

121121
[compose]: https://developer.android.com/jetpack/compose
122122
[mdc]: https://material.io/develop/android/
123-
[materialtheme]: https://developer.android.com/reference/kotlin/androidx/ui/material/MaterialTheme
124-
[shapes]: https://developer.android.com/reference/kotlin/androidx/ui/material/Shapes
123+
[materialtheme]: https://developer.android.com/reference/kotlin/androidx/compose/material/MaterialTheme
124+
[shapes]: https://developer.android.com/reference/kotlin/androidx/compose/material/Shapes
125+
[colors]: https://developer.android.com/reference/kotlin/androidx/compose/material/Colors
126+
[typography]: https://developer.android.com/reference/kotlin/androidx/compose/material/Typography

build.gradle

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.google.android.material.composethemeadapter.Versions
2020
buildscript {
2121
repositories {
2222
google()
23+
mavenCentral()
2324
jcenter()
2425
}
2526

@@ -32,7 +33,7 @@ buildscript {
3233
}
3334

3435
plugins {
35-
id "com.diffplug.gradle.spotless" version "4.3.0"
36+
id "com.diffplug.spotless" version "5.1.1"
3637
}
3738

3839
subprojects {
@@ -48,7 +49,7 @@ subprojects {
4849
}
4950
}
5051

51-
apply plugin: 'com.diffplug.gradle.spotless'
52+
apply plugin: 'com.diffplug.spotless'
5253
spotless {
5354
kotlin {
5455
target "**/*.kt"
@@ -68,15 +69,7 @@ subprojects {
6869
// Allow use of @OptIn
6970
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
7071

71-
// Compose is now based on the Kotlin 1.4 compiler, but we need to use the 1.3.x Kotlin
72-
// library due to library compatibility, etc. Therefore we explicit set our apiVersion
73-
// to 1.3 to fix any warnings. Binary dependencies (such as Compose) can continue to
74-
// use 1.4 if built with that library
75-
apiVersion = "1.3"
76-
77-
// Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit`
78-
// TODO: Remove when we move to Kotlin 1.4
79-
freeCompilerArgs += "-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes"
72+
freeCompilerArgs += "-Xallow-jvm-ir-dependencies"
8073
}
8174
}
8275
}

buildSrc/src/main/java/com/google/android/material/composethemeadapter/dependencies.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,32 @@ object Versions {
2121
}
2222

2323
object Libs {
24-
const val androidGradlePlugin = "com.android.tools.build:gradle:4.2.0-alpha05"
24+
const val androidGradlePlugin = "com.android.tools.build:gradle:4.2.0-alpha07"
2525

2626
const val gradleMavenPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.12.0"
2727

2828
const val mdc = "com.google.android.material:material:1.1.0"
2929

3030
object Kotlin {
31-
private const val version = "1.3.72"
31+
const val version = "1.4.0-rc"
3232
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"
3333
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
3434
}
3535

3636
object AndroidX {
3737
object Compose {
3838
const val snapshot = ""
39-
const val version = "0.1.0-dev14"
40-
const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
39+
const val version = "0.1.0-dev16"
4140

42-
const val runtime = "androidx.compose:compose-runtime:$version"
41+
const val runtime = "androidx.compose.runtime:runtime:$version"
42+
const val foundation = "androidx.compose.foundation:foundation:${version}"
43+
const val layout = "androidx.compose.foundation:foundation-layout:${version}"
4344

44-
const val layout = "androidx.ui:ui-layout:$version"
45-
const val material = "androidx.ui:ui-material:$version"
45+
const val ui = "androidx.compose.ui:ui:${version}"
46+
const val material = "androidx.compose.material:material:${version}"
4647

47-
const val test = "androidx.ui:ui-test:$version"
48+
const val tooling = "androidx.ui:ui-tooling:${version}"
49+
const val test = "androidx.ui:ui-test:${version}"
4850
}
4951

5052
const val coreKtx = "androidx.core:core-ktx:1.2.0"

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ android {
3838
}
3939

4040
composeOptions {
41-
kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion
41+
kotlinCompilerVersion Libs.Kotlin.version
4242
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version
4343
}
4444

lib/src/androidTest/java/com/google/android/material/composethemeadapter/MdcThemeTest.kt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616

1717
package com.google.android.material.composethemeadapter
1818

19+
import androidx.compose.foundation.isSystemInDarkTheme
20+
import androidx.compose.foundation.shape.CornerSize
21+
import androidx.compose.foundation.shape.CutCornerShape
22+
import androidx.compose.foundation.shape.RoundedCornerShape
23+
import androidx.compose.material.MaterialTheme
24+
import androidx.compose.ui.geometry.Size
25+
import androidx.compose.ui.platform.DensityAmbient
26+
import androidx.compose.ui.res.colorResource
27+
import androidx.compose.ui.text.font.asFontFamily
28+
import androidx.compose.ui.text.font.font
29+
import androidx.compose.ui.unit.Density
30+
import androidx.compose.ui.unit.Dp
31+
import androidx.compose.ui.unit.TextUnit
32+
import androidx.compose.ui.unit.dp
33+
import androidx.compose.ui.unit.em
34+
import androidx.compose.ui.unit.sp
1935
import androidx.test.filters.MediumTest
20-
import androidx.ui.core.DensityAmbient
21-
import androidx.ui.foundation.shape.corner.CornerSize
22-
import androidx.ui.foundation.shape.corner.CutCornerShape
23-
import androidx.ui.foundation.shape.corner.RoundedCornerShape
24-
import androidx.ui.geometry.Size
25-
import androidx.ui.material.MaterialTheme
26-
import androidx.ui.res.colorResource
27-
import androidx.ui.test.android.AndroidComposeTestRule
28-
import androidx.ui.text.font.asFontFamily
29-
import androidx.ui.text.font.font
30-
import androidx.ui.unit.Density
31-
import androidx.ui.unit.Dp
32-
import androidx.ui.unit.TextUnit
33-
import androidx.ui.unit.dp
34-
import androidx.ui.unit.em
35-
import androidx.ui.unit.sp
36+
import androidx.ui.test.android.createAndroidComposeRule
3637
import com.google.android.material.composethemeadapter.test.R
3738
import org.junit.Assert.assertEquals
3839
import org.junit.Assert.assertNotNull
@@ -47,7 +48,7 @@ import org.junit.runners.JUnit4
4748
@RunWith(JUnit4::class)
4849
class MdcThemeTest {
4950
@get:Rule
50-
val composeTestRule = AndroidComposeTestRule<MdcActivity>()
51+
val composeTestRule = createAndroidComposeRule<MdcActivity>()
5152

5253
@Test
5354
fun colors() = composeTestRule.setContent {
@@ -59,8 +60,13 @@ class MdcThemeTest {
5960
assertEquals(colorResource(R.color.midnight_blue), color.onPrimary)
6061

6162
assertEquals(colorResource(R.color.dark_golden_rod), color.secondary)
62-
assertEquals(colorResource(R.color.blue_violet), color.secondaryVariant)
6363
assertEquals(colorResource(R.color.slate_gray), color.onSecondary)
64+
if (!isSystemInDarkTheme()) {
65+
assertEquals(colorResource(R.color.blue_violet), color.secondaryVariant)
66+
} else {
67+
// In dark theme secondaryVariant is ignored and always return secondary
68+
assertEquals(colorResource(R.color.dark_golden_rod), color.secondaryVariant)
69+
}
6470

6571
assertEquals(colorResource(R.color.spring_green), color.surface)
6672
assertEquals(colorResource(R.color.navy), color.onSurface)
@@ -158,4 +164,4 @@ private fun assertTextUnitEquals(expected: TextUnit, actual: TextUnit, density:
158164
}
159165
}
160166

161-
private fun CornerSize.toPx(density: Density) = toPx(Size.UnspecifiedSize, density)
167+
private fun CornerSize.toPx(density: Density) = toPx(Size.Unspecified, density)

lib/src/androidTest/java/com/google/android/material/composethemeadapter/NotMdcThemeTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.android.material.composethemeadapter
1818

1919
import androidx.test.filters.MediumTest
20-
import androidx.ui.test.android.AndroidComposeTestRule
20+
import androidx.ui.test.android.createAndroidComposeRule
2121
import org.junit.Rule
2222
import org.junit.Test
2323
import org.junit.runner.RunWith
@@ -27,7 +27,7 @@ import org.junit.runners.JUnit4
2727
@RunWith(JUnit4::class)
2828
class NotMdcThemeTest {
2929
@get:Rule
30-
val composeTestRule = AndroidComposeTestRule<NotMdcActivity>()
30+
val composeTestRule = createAndroidComposeRule<NotMdcActivity>()
3131

3232
@Test(expected = IllegalArgumentException::class)
3333
fun throwForNonMdcTheme() = composeTestRule.setContent {

0 commit comments

Comments
 (0)