You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug org.jetbrains.compose.resources.Font composable is ignorant to updated resource value.
This is Android only issue, but it's not reproduced on regular compose - it's related to using shared resources from common part.
Affected platforms
Android
Versions
Libraries:
Compose Multiplatform version: 1.6.10
Kotlin version: 2.0.0
OS architecture (x86 or arm64): arm64
Device (model or simulator for iOS issues): Android emulator
To Reproduce
Steps to reproduce the behavior:
Put fonts in commonMain/composeResources/font/ folder, so Res.font is autogenerated.
Run this code snippet:
var flag by remember {
mutableStateOf(false)
}
Column {
Text(
"hey",
fontFamily =FontFamily(Font(if (flag) Res.font.HelveticaNeueMediumelseRes.font.COMICSANS, FontWeight.Normal))
)
Switch(checked = flag, onCheckedChange = { flag = it })
}
Click on Switch
Expected behavior
Text font is changed
Additional context
As you can see in the source code of org.jetbrains.compose.resources.Font composable, it remembers result of getResourceItemByEnvironment and doesn't update it in case new resource value is passed.
On other platforms it's not an issue because resource value is passed into rememberResourceState.
Suggested fix is passing resource to remember:
val path = remember(environment, resource) { resource.getResourceItemByEnvironment(environment).path }
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
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
(cherry picked from commit 0485f03)
Describe the bug
org.jetbrains.compose.resources.Font
composable is ignorant to updatedresource
value.This is Android only issue, but it's not reproduced on regular compose - it's related to using shared resources from common part.
Affected platforms
Versions
To Reproduce
Steps to reproduce the behavior:
commonMain/composeResources/font/
folder, soRes.font
is autogenerated.Expected behavior
Text font is changed
Additional context
As you can see in the source code of
org.jetbrains.compose.resources.Font
composable, it remembers result ofgetResourceItemByEnvironment
and doesn't update it in case newresource
value is passed.On other platforms it's not an issue because
resource
value is passed intorememberResourceState
.Suggested fix is passing
resource
toremember
:Related stackoverflow question.
The text was updated successfully, but these errors were encountered: