Hello, what’s the recommended approach to load fonts on a CMP project with the following targets: android, desktop and wasm?
common:
@Composable
expect fun platformFont(resourceId: String, weight: FontWeight, style: FontStyle): Font
androidMain:
private val idCache = mutableMapOf<String, Int>()
@Composable
actual fun platformFont(resourceId: String, weight: FontWeight, style: FontStyle): Font {
val context = LocalContext.current
val id = idCache.getOrPut(resourceId) {
context.resources.getIdentifier(resourceId, "fonts", context.packageName)
}
return Font(resId = id, weight = weight, style = style)
}
desktopMain:
@Composable
actual fun platformFont(resourceId: String, weight: FontWeight, style: FontStyle): Font =
androidx.compose.ui.text.platform.Font("font/${resourceId}.ttf", weight, style)
I can make it work with the above setup (even for iOS), but I’ve no clue how to do it for wasm 😞 any help? Thanks!