Hello, what’s the recommended approach to load fon...
# compose-web
g
Hello, what’s the recommended approach to load fonts on a CMP project with the following targets: android, desktop and wasm? common:
Copy code
@Composable
expect fun platformFont(resourceId: String, weight: FontWeight, style: FontStyle): Font
androidMain:
Copy code
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:
Copy code
@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!
👍 1
g
Damn, found a lot of samples and etc, but not that page 😓 Thanks @Konstantin Tskhovrebov I’ll give it a look.
Regarding XML Vector Drawables how can I transform this:
Copy code
<vector xmlns:android="<http://schemas.android.com/apk/res/android>" <<<<<<<<<
        android:width="38dp"
        android:height="46dp"
        android:viewportWidth="38"
        android:viewportHeight="46">
to be accepted in commonMain?
Screenshot 2024-02-17 at 14.13.24.png
or can it be ignored?
Hello @Konstantin Tskhovrebov quick question 🙂 Docs say that: > Multimodule projects are not supported yet. The JetBrains team is working on adding this functionality in future releases. For now, store all resources in the main application module. by Multimodule you refer to having a module with the composables, let’s say “shared-ui”, and then a module per target (ex: desktopApp, wasmApp, androidApp, iosApp) that depend on this “shared-ui” to use the desired composables, correct? I’m creating a small poc and yes - wasm and Android doesn’t work -, but desktop does. Any reason?