Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi previews #147

Merged
merged 8 commits into from May 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions audio-ui/build.gradle
Expand Up @@ -112,13 +112,12 @@ dependencies {
implementation libs.androidx.wear
implementation libs.androidx.lifecycle.viewmodel.compose

debugImplementation libs.androidx.customview
debugImplementation libs.androidx.customview.pooling
debugImplementation libs.compose.ui.toolingpreview
debugImplementation libs.androidx.activity.compose
debugImplementation projects.composeTesting

testImplementation libs.junit
testImplementation projects.paparazzi
testImplementation projects.composeTesting

androidTestImplementation libs.compose.ui.test.junit4
debugImplementation libs.compose.ui.test.manifest
Expand Down
Expand Up @@ -27,6 +27,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.wear.compose.material.Scaffold
import com.google.android.horologist.audio.AudioOutput
import com.google.android.horologist.audio.VolumeState
import com.google.android.horologist.compose.testing.WearPreviewDevices
import com.google.android.horologist.compose.testing.WearPreviewFontSizes

@Preview(
device = Devices.WEAR_OS_LARGE_ROUND,
Expand Down Expand Up @@ -60,24 +62,8 @@ fun VolumeScreenGuide() {
}
}

@Preview(
device = Devices.WEAR_OS_LARGE_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true
)
@Preview(
device = Devices.WEAR_OS_SQUARE,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true
)
@WearPreviewDevices
@WearPreviewFontSizes
@Composable
@OptIn(ExperimentalHorologistAudioUiApi::class)
fun VolumeScreenPreview(
Expand Down
2 changes: 0 additions & 2 deletions composables/build.gradle
Expand Up @@ -86,8 +86,6 @@ dependencies {
implementation libs.compose.material.iconscore
implementation libs.compose.material.iconsext

debugImplementation libs.androidx.customview
debugImplementation libs.androidx.customview.pooling
debugImplementation libs.compose.ui.test.manifest
debugImplementation libs.compose.ui.toolingpreview

Expand Down
1 change: 1 addition & 0 deletions compose-layout/build.gradle
Expand Up @@ -105,6 +105,7 @@ dependencies {
implementation libs.compose.ui.util
implementation libs.androidx.wear
implementation libs.androidx.lifecycle.viewmodel.compose
debugImplementation projects.composeTesting
debugImplementation libs.compose.ui.toolingpreview
debugImplementation libs.androidx.activity.compose

Expand Down
Expand Up @@ -24,22 +24,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.wear.compose.material.Text
import com.google.android.horologist.compose.testing.WearPreviewDevices

@Preview(
device = Devices.WEAR_OS_LARGE_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true
)
@Preview(
device = Devices.WEAR_OS_SQUARE,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true
)
@WearPreviewDevices
@Composable
fun Preview() {
Box(modifier = Modifier.fillMaxSize()) {
Expand Down
22 changes: 22 additions & 0 deletions compose-testing/README.md
@@ -0,0 +1,22 @@
# Testing Library

[![Maven Central](https://img.shields.io/maven-central/v/com.google.android.horologist/horologist-compose-testing)](https://search.maven.org/search?q=g:com.google.android.horologist)

For more information, visit the documentation: https://google.github.io/horologist/compose-testing

## Download

```groovy
repositories {
mavenCentral()
}

dependencies {
implementation "com.google.android.horologist:horologist-compose-testing:<version>"
}
```

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap].
These are updated on every commit.

[snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/android/horologist/horologist-compose-testing/
11 changes: 11 additions & 0 deletions compose-testing/api/current.api
@@ -0,0 +1,11 @@
// Signature format: 4.0
package com.google.android.horologist.compose.testing {

@androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_LARGE_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Large Round") @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Small Round") @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SQUARE, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Square") public @interface WearPreviewDevices {
}

@androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Small", fontScale=0.94f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Normal", fontScale=1.0f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Medium", fontScale=1.06f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Large", fontScale=1.12f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Larger", fontScale=1.18f) @androidx.compose.ui.tooling.preview.Preview(device=androidx.compose.ui.tooling.preview.Devices.WEAR_OS_SMALL_ROUND, showSystemUi=true, backgroundColor=4278190080L, showBackground=true, name="Largest", fontScale=1.24f) public @interface WearPreviewFontSizes {
}

}

107 changes: 107 additions & 0 deletions compose-testing/build.gradle
@@ -0,0 +1,107 @@
/*
* Copyright 2022 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.
*/

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.dokka'
id "org.jetbrains.kotlin.kapt"
}

android {
compileSdkVersion 31

defaultConfig {
minSdk 25
targetSdk 30
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildFeatures {
buildConfig false
}

kotlinOptions {
jvmTarget = "1.8"
}

composeOptions {
kotlinCompilerExtensionVersion libs.versions.compose.get()
}

lintOptions {
textReport true
textOutput 'stdout'
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks
checkReleaseBuilds false
}

packagingOptions {
// Some of the META-INF files conflict with coroutines-test. Exclude them to enable
// our test APK to build (has no effect on our AARs)
excludes += "/META-INF/AL2.0"
excludes += "/META-INF/LGPL2.1"
}

testOptions {
unitTests {
includeAndroidResources = true
}
animationsDisabled true
}

sourceSets {
test {
java.srcDirs += 'src/sharedTest/kotlin'
res.srcDirs += 'src/sharedTest/res'
}
androidTest {
java.srcDirs += 'src/sharedTest/kotlin'
res.srcDirs += 'src/sharedTest/res'
}
}
}

kapt {
correctErrorTypes true
}

project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile.class).configureEach { task ->
// Workaround for https://youtrack.jetbrains.com/issue/KT-37652
if (!task.name.endsWith("TestKotlin") && !task.name.startsWith("compileDebug")) {
task.kotlinOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

dependencies {
implementation libs.kotlin.stdlib

implementation libs.compose.ui.tooling

implementation libs.wearcompose.material
implementation libs.wearcompose.foundation
implementation libs.wearcompose.navigation

debugImplementation libs.compose.ui.test.manifest
debugImplementation libs.compose.ui.toolingpreview
}

apply plugin: "com.vanniktech.maven.publish"
3 changes: 3 additions & 0 deletions compose-testing/gradle.properties
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=horologist-compose-testing
POM_NAME=Horologist Compose Testing library
POM_PACKAGING=aar
21 changes: 21 additions & 0 deletions compose-testing/src/main/AndroidManifest.xml
@@ -0,0 +1,21 @@
<!--
~ Copyright 2022 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.horologist.compose.testing">

<uses-feature android:name="android.hardware.type.watch" />
</manifest>
@@ -0,0 +1,43 @@
/*
* Copyright 2022 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 com.google.android.horologist.compose.testing

import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview

@Preview(
device = Devices.WEAR_OS_LARGE_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Devices - Large Round",
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Devices - Small Round",
)
@Preview(
device = Devices.WEAR_OS_SQUARE,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Devices - Square",
)
public annotation class WearPreviewDevices
@@ -0,0 +1,70 @@
/*
* Copyright 2022 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 com.google.android.horologist.compose.testing

import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview

@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Small",
fontScale = 0.94f
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Normal",
fontScale = 1f
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Medium",
fontScale = 1.06f
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Large",
fontScale = 1.12f
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Larger",
fontScale = 1.18f
)
@Preview(
device = Devices.WEAR_OS_SMALL_ROUND,
showSystemUi = true,
backgroundColor = 0xff000000,
showBackground = true,
group = "Fonts - Largest",
fontScale = 1.24f
)
public annotation class WearPreviewFontSizes
2 changes: 0 additions & 2 deletions media-ui/build.gradle
Expand Up @@ -91,8 +91,6 @@ dependencies {
implementation libs.compose.material.iconsext
implementation libs.androidx.media3.common

debugImplementation libs.androidx.customview
debugImplementation libs.androidx.customview.pooling
debugImplementation libs.compose.ui.test.manifest
debugImplementation libs.compose.ui.toolingpreview

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -34,6 +34,7 @@ include ':tiles'
include ':media-ui'
include ':paparazzi'
include ':media-data'
include ':compose-testing'

// Enable Gradle's version catalog support
// https://docs.gradle.org/current/userguide/platforms.html
Expand Down