DeviceConfigurationOverride

Functions summary

Unit

Applies DeviceConfigurationOverride to the content under test to apply some configuration override.

Cmn

Functions

DeviceConfigurationOverride

@Composable
fun DeviceConfigurationOverride(
    override: DeviceConfigurationOverride,
    content: @Composable () -> Unit
): Unit

Applies DeviceConfigurationOverride to the content under test to apply some configuration override.

This can be useful to locally test behavior in isolation that depends on properties that are normally device-wide, such as font scale, screen size and layout direction.

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
}
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
}
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
}
Parameters
override: DeviceConfigurationOverride

the DeviceConfigurationOverride to apply

content: @Composable () -> Unit

the content under test to apply the override to