From b097f30fced59d98dfcb157c2af4357a598b7c0e Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Tue, 27 Feb 2024 14:43:31 -0800 Subject: [PATCH 1/2] Add DeviceConfigurationOverride snippets --- .../DeviceConfigurationOverrideSnippets.kt | 65 +++++++++++++++++++ gradle/libs.versions.toml | 3 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt diff --git a/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt b/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt new file mode 100644 index 000000000..36db665a1 --- /dev/null +++ b/compose/snippets/src/androidTest/java/com/example/compose/snippets/deviceconfigurationoverride/DeviceConfigurationOverrideSnippets.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2024 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.example.compose.snippets.deviceconfigurationoverride + +import androidx.compose.material3.Text +import androidx.compose.ui.test.DeviceConfigurationOverride +import androidx.compose.ui.test.FontScale +import androidx.compose.ui.test.FontWeightAdjustment +import androidx.compose.ui.test.ForcedSize +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.then +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import com.example.compose.snippets.interop.MyScreen +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test + +class DeviceConfigurationOverrideSnippetsTest { + @get:Rule + val composeTestRule = createComposeRule() + + @Ignore("Snippet test") + @Test + fun forcedSize() { + // [START android_compose_deviceconfigurationoverride_forcedsize] + composeTestRule.setContent { + DeviceConfigurationOverride( + DeviceConfigurationOverride.ForcedSize(DpSize(1280.dp, 800.dp)) + ) { + MyScreen() // will be rendered in the space for 1280dp by 800dp without clipping + } + } + // [END android_compose_deviceconfigurationoverride_forcedsize] + } + + @Ignore("Snippet test") + @Test + fun then() { + // [START android_compose_deviceconfigurationoverride_then] + composeTestRule.setContent { + DeviceConfigurationOverride( + DeviceConfigurationOverride.FontScale(1.5f) then + DeviceConfigurationOverride.FontWeightAdjustment(200) + ) { + Text(text = "text with increased scale and weight") + } + } + // [END android_compose_deviceconfigurationoverride_then] + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 035b5f151..285665756 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,7 @@ androidGradlePlugin = "8.2.2" androidx-activity-compose = "1.9.0-alpha03" androidx-appcompat = "1.6.1" androidx-compose-bom = "2024.02.01" +androidx-compose-ui-test = "1.7.0-alpha03" androidx-constraintlayout = "2.1.4" androidx-constraintlayout-compose = "1.0.1" androidx-coordinator-layout = "1.2.0" @@ -68,7 +69,7 @@ androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime androidx-compose-ui = { module = "androidx.compose.ui:ui" } androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" } androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" } -androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" } +androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test", version.ref = "androidx-compose-ui-test" } androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" } androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" } androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } From b0d5ff04d972f338f1fa4b2fd1cf9c7dab1b0ebe Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Wed, 28 Feb 2024 07:16:41 -0800 Subject: [PATCH 2/2] Add TODO for ui-test version once 1.7 is stable --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 285665756..068d1cb8a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ androidGradlePlugin = "8.2.2" androidx-activity-compose = "1.9.0-alpha03" androidx-appcompat = "1.6.1" androidx-compose-bom = "2024.02.01" -androidx-compose-ui-test = "1.7.0-alpha03" +androidx-compose-ui-test = "1.7.0-alpha03" # TODO: Remove once 1.7 is stable androidx-constraintlayout = "2.1.4" androidx-constraintlayout-compose = "1.0.1" androidx-coordinator-layout = "1.2.0"