DeviceConfigurationOverride.Companion



Summary

Extension functions

DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the dark mode or light mode theme for the contained content.

android
DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the font scale for the contained content.

Cmn
android
DeviceConfigurationOverride
@RequiresApi(value = 31)
DeviceConfigurationOverride.Companion.FontWeightAdjustment(
    fontWeightAdjustment: Int
)

A DeviceConfigurationOverride that overrides the font weight adjustment for the contained content.

android
DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the available size for the contained content.

Cmn
android
DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the layout direction for the contained content.

Cmn
android
DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the locales for the contained content.

android
DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides whether the screen is round for the contained content.

android

Extension functions

DarkMode

fun DeviceConfigurationOverride.Companion.DarkMode(isDarkMode: Boolean): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the dark mode or light mode theme for the contained content. Inside the content under test, isSystemInDarkTheme() will return isDarkMode.

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.ui.test.DarkMode
import androidx.compose.ui.test.DeviceConfigurationOverride

DeviceConfigurationOverride(
    DeviceConfigurationOverride.DarkMode(true)
) {
    isSystemInDarkTheme() // will be true
}

FontScale

fun DeviceConfigurationOverride.Companion.FontScale(fontScale: Float): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the font scale for the contained content.

import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.FontScale

DeviceConfigurationOverride(
    DeviceConfigurationOverride.FontScale(1.5f)
) {
    MyScreen() // will be rendered with a larger than default font scale
}

FontWeightAdjustment

@RequiresApi(value = 31)
fun DeviceConfigurationOverride.Companion.FontWeightAdjustment(
    fontWeightAdjustment: Int
): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the font weight adjustment for the contained content.

import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.FontWeightAdjustment

DeviceConfigurationOverride(
    DeviceConfigurationOverride.FontWeightAdjustment(200)
) {
    MyComponent() // will be rendered with adjusted font weight
}

ForcedSize

fun DeviceConfigurationOverride.Companion.ForcedSize(size: DpSize): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the available size for the contained content.

This is only suitable for tests, since this will override LocalDensity to ensure that the size is met (as opposed to Modifier.requiredSize which will result in clipping).

import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.ForcedSize
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp

DeviceConfigurationOverride(
    DeviceConfigurationOverride.ForcedSize(DpSize(1280.dp, 800.dp))
) {
    MyScreen() // will be rendered in the space for 1280dp by 800dp without clipping
}

LayoutDirection

fun DeviceConfigurationOverride.Companion.LayoutDirection(
    layoutDirection: LayoutDirection
): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the layout direction for the contained content.

import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.LayoutDirection
import androidx.compose.ui.unit.LayoutDirection

DeviceConfigurationOverride(
    DeviceConfigurationOverride.LayoutDirection(LayoutDirection.Rtl)
) {
    MyComponent() // will be rendered with a right-to-left layout direction
}

Locales

fun DeviceConfigurationOverride.Companion.Locales(locales: LocaleList): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides the locales for the contained content.

This will change resource resolution for the content under test, and also override the layout direction as specified by the locales.

import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.Locales
import androidx.compose.ui.text.intl.LocaleList

DeviceConfigurationOverride(
    DeviceConfigurationOverride.Locales(LocaleList("es-ES"))
) {
    MyScreen() // will be rendered with overridden locale
}

RoundScreen

@RequiresApi(value = 23)
fun DeviceConfigurationOverride.Companion.RoundScreen(
    isScreenRound: Boolean
): DeviceConfigurationOverride

A DeviceConfigurationOverride that overrides whether the screen is round for the contained content.

import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.test.DeviceConfigurationOverride
import androidx.compose.ui.test.RoundScreen

DeviceConfigurationOverride(
    DeviceConfigurationOverride.RoundScreen(true)
) {
    LocalConfiguration.current.isScreenRound // will be true
}