From b26c995aece864c8188b5724f8c2491ffcfa55bc Mon Sep 17 00:00:00 2001 From: Philip Dukhov Date: Mon, 27 May 2024 18:50:55 +0700 Subject: [PATCH] [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 (cherry picked from commit 0485f03f424d556ac8f23187b837c16eede2b6a2) --- .../org/jetbrains/compose/resources/FontResources.android.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt index c85d34c1e8..009419a020 100644 --- a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt +++ b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/FontResources.android.kt @@ -8,6 +8,6 @@ import androidx.compose.ui.text.font.* @Composable actual fun Font(resource: FontResource, weight: FontWeight, style: FontStyle): Font { 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) } \ No newline at end of file