Browse Source

[Android] update Font with new resource value (#4864)

Fixes #4863

Before this update, when a new `resource` value was passed to
`org.jetbrains.compose.resources.Font` composable, it kept the original
value.

Test sample code. `Res.font` here is autogenerated from
`commonMain/composeResources/font/` folder content.
```kt
var flag by remember {
    mutableStateOf(false)
}
Column {
    Text(
        "hey",
        fontFamily = FontFamily(Font(if (flag) Res.font.HelveticaNeueMedium else Res.font.COMICSANS, FontWeight.Normal))
    )
    Switch(checked = flag, onCheckedChange = { flag = it })
}
```

## Release Notes
### Fixes - Resources
- Fix a cached font if the resource acessor was changed
pull/4879/head
Philip Dukhov 6 months ago committed by GitHub
parent
commit
0485f03f42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt

2
components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt

@ -8,6 +8,6 @@ import androidx.compose.ui.text.font.*
@Composable @Composable
actual fun Font(resource: FontResource, weight: FontWeight, style: FontStyle): Font { actual fun Font(resource: FontResource, weight: FontWeight, style: FontStyle): Font {
val environment = LocalComposeEnvironment.current.rememberEnvironment() val environment = LocalComposeEnvironment.current.rememberEnvironment()
val path = remember(environment) { resource.getResourceItemByEnvironment(environment).path } val path = remember(environment, resource) { resource.getResourceItemByEnvironment(environment).path }
return Font(path, LocalContext.current.assets, weight, style) return Font(path, LocalContext.current.assets, weight, style)
} }
Loading…
Cancel
Save