Skip to content

Qualified night/dark assets not being picked up in @Preview snapshot tests #377

@drinkthestars

Description

@drinkthestars

Given the following:

@Preview(name = "TestBox - Light")
@Composable
fun TestPreviewLight() {
    TestBox()
}

@Preview(name = "TestBox - Dark", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun TestPreviewDark() {
    TestBox()
}

@Composable
fun TestBox(
    modifier: Modifier = Modifier
) {
    Box(
        modifier = modifier.size(100.dp)
    ) {
        Image(
            imageVector = ImageVector.vectorResource(id = R.drawable.test_drawable),
            contentDescription = "Testing background",
        )
    }
}

where the R.drawable.test_drawable is a vector that references night/day qualified colors or has a drawable-night equivalent, the recorded snapshots only show the light variant - somehow the dark/night qualified assets are not being picked up:

Preview:
Screenshot 2024-04-04 at 1 53 35 AM

Golden Snapshots:
Screenshot 2024-04-04 at 1 52 45 AM

Tried the following to try to force it, but didn't work either:

@Preview...
fun TestPreview() {
    val customConfiguration = Configuration(LocalConfiguration.current).apply {
        uiMode = Configuration.UI_MODE_NIGHT_YES
    }
    CompositionLocalProvider(LocalConfiguration provides customConfiguration) {
        TestBox()
    }
}

Is this a bug/limitation or is it a config issue? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions