Skip to content

Commit a284f31

Browse files
authored
Add DeviceConfigurationOverride snippets (#228)
* Add DeviceConfigurationOverride snippets * Add TODO for ui-test version once 1.7 is stable
1 parent 695d9bb commit a284f31

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.compose.snippets.deviceconfigurationoverride
18+
19+
import androidx.compose.material3.Text
20+
import androidx.compose.ui.test.DeviceConfigurationOverride
21+
import androidx.compose.ui.test.FontScale
22+
import androidx.compose.ui.test.FontWeightAdjustment
23+
import androidx.compose.ui.test.ForcedSize
24+
import androidx.compose.ui.test.junit4.createComposeRule
25+
import androidx.compose.ui.test.then
26+
import androidx.compose.ui.unit.DpSize
27+
import androidx.compose.ui.unit.dp
28+
import com.example.compose.snippets.interop.MyScreen
29+
import org.junit.Ignore
30+
import org.junit.Rule
31+
import org.junit.Test
32+
33+
class DeviceConfigurationOverrideSnippetsTest {
34+
@get:Rule
35+
val composeTestRule = createComposeRule()
36+
37+
@Ignore("Snippet test")
38+
@Test
39+
fun forcedSize() {
40+
// [START android_compose_deviceconfigurationoverride_forcedsize]
41+
composeTestRule.setContent {
42+
DeviceConfigurationOverride(
43+
DeviceConfigurationOverride.ForcedSize(DpSize(1280.dp, 800.dp))
44+
) {
45+
MyScreen() // will be rendered in the space for 1280dp by 800dp without clipping
46+
}
47+
}
48+
// [END android_compose_deviceconfigurationoverride_forcedsize]
49+
}
50+
51+
@Ignore("Snippet test")
52+
@Test
53+
fun then() {
54+
// [START android_compose_deviceconfigurationoverride_then]
55+
composeTestRule.setContent {
56+
DeviceConfigurationOverride(
57+
DeviceConfigurationOverride.FontScale(1.5f) then
58+
DeviceConfigurationOverride.FontWeightAdjustment(200)
59+
) {
60+
Text(text = "text with increased scale and weight")
61+
}
62+
}
63+
// [END android_compose_deviceconfigurationoverride_then]
64+
}
65+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ androidGradlePlugin = "8.2.2"
44
androidx-activity-compose = "1.9.0-alpha03"
55
androidx-appcompat = "1.6.1"
66
androidx-compose-bom = "2024.02.01"
7+
androidx-compose-ui-test = "1.7.0-alpha03" # TODO: Remove once 1.7 is stable
78
androidx-constraintlayout = "2.1.4"
89
androidx-constraintlayout-compose = "1.0.1"
910
androidx-coordinator-layout = "1.2.0"
@@ -68,7 +69,7 @@ androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime
6869
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
6970
androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" }
7071
androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
71-
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" }
72+
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test", version.ref = "androidx-compose-ui-test" }
7273
androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" }
7374
androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
7475
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }

0 commit comments

Comments
 (0)