Skip to content

Add DeviceConfigurationOverride snippets #228

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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]
}
}
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" # TODO: Remove once 1.7 is stable
androidx-constraintlayout = "2.1.4"
androidx-constraintlayout-compose = "1.0.1"
androidx-coordinator-layout = "1.2.0"
Expand Down Expand Up @@ -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" }
Expand Down