Joel Denke
05/31/2023, 5:28 AMprivate val cache: MutableMap<String, Font> = mutableMapOf()
@Composable
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font {
return cache.getOrPut(res) {
val byteArray = runBlocking {
try {
resource("$res.ttf").readBytes()
} catch (e: Exception) {
resource("$res.otf").readBytes()
}
}
Font(res, byteArray, weight, style)
}
}
I put all my files (font files with .ttf file extension that is) into src/commonMain/resources/font
but its never found regardless if I am using font("MyName", "font/myname", FontWeight.Bold, FontStyle.Normal)
or something else.
I always getting resource not found from resources.
I think could be something with my setup with cocoapods but not sure what I could have been missing. Do I need to link it in a certain way? I have static = true.
Had similar issues in Android where the problem was I had to change to snake case and put into font folder, to let Android extract the resources into res folder.Joel Denke
05/31/2023, 5:29 AMcocoapods {
version = "1.0"
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
name = "common"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "common"
isStatic = true
}
extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**', 'src/commonMain/resources/font/**']"
}
Oleksandr Karpovich [JB]
05/31/2023, 11:22 AMfont(...)
function work if the font.ttf
file is in src/commonMain/resources folder? It should work from resources/font directory as well, but I would check anyway.
What's in the byteArray?Joel Denke
05/31/2023, 11:31 AMJoel Denke
05/31/2023, 11:32 AMOleksandr Karpovich [JB]
05/31/2023, 11:37 AMJoel Denke
05/31/2023, 11:40 AMJoel Denke
05/31/2023, 11:41 AMJoel Denke
05/31/2023, 11:42 AMOleksandr Karpovich [JB]
05/31/2023, 11:42 AMJoel Denke
05/31/2023, 11:48 AMJoel Denke
05/31/2023, 11:50 AMOleksandr Karpovich [JB]
05/31/2023, 11:52 AMCan probably share parts of it.It would help a lot 🙂 If you manage to do it, please add it here https://github.com/JetBrains/compose-multiplatform/issues
Oleksandr Karpovich [JB]
05/31/2023, 11:54 AMJoel Denke
05/31/2023, 11:56 AMJoel Denke
05/31/2023, 1:18 PMOleksandr Karpovich [JB]
05/31/2023, 1:19 PMJoel Denke
05/31/2023, 1:20 PMJoel Denke
05/31/2023, 1:32 PMOleksandr Karpovich [JB]
05/31/2023, 1:36 PMOleksandr Karpovich [JB]
05/31/2023, 1:38 PMJoel Denke
05/31/2023, 2:08 PMJoel Denke
05/31/2023, 2:09 PMJoel Denke
05/31/2023, 2:10 PMJoel Denke
05/31/2023, 2:11 PMJoel Denke
05/31/2023, 2:12 PMOleksandr Karpovich [JB]
05/31/2023, 2:24 PMextraSpecAttributes["resources"] = "['src/commonMain/resources/fonts/**', 'src/commonMain/resources/**', 'src/iosMain/resources/**']"
• Added pod 'otherPod', :path => '../otherPod'
in Podfile
• Added import otherPod
in ContentView.swift file (didn’t work without it for some reason…, maybe a glitch)
• Added otherPod/commonMain/resource/fonts/karla_regular.ttf
Checking what’s in the bundle:
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let resourcePath = Bundle.main.resourcePath!
do {
let resourceFiles = try FileManager.default.contentsOfDirectory(atPath: resourcePath)
print("Resources: \(resourceFiles)")
} catch let error as NSError {
print("Error: \(error)")
}
return Main_iosKt.MainViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
And the font file is printed:
Resources: ["_CodeSignature", "karla_regular.ttf", "My application", "img123.xml", "compose-multiplatform.xml", "AppIcon60x60@2x.png", "Assets.car", "AppIcon76x76@2x~ipad.png", "fonts", "Info.plist", "PkgInfo"]
Now I’ll try to load it in the app code.
Also I ran the cleanup.sh script before retrying to run the appOleksandr Karpovich [JB]
05/31/2023, 2:46 PMJoel Denke
05/31/2023, 3:24 PMJoel Denke
05/31/2023, 3:26 PMOleksandr Karpovich [JB]
05/31/2023, 3:27 PMJoel Denke
05/31/2023, 3:28 PMJoel Denke
05/31/2023, 3:29 PMxcodebuild: error: '/Users/myuser/StudioProjects/mobile-app/iosApp/iosApp.xcworkspace' does not exist.
lol
Do I need to re-add that part somehow?Joel Denke
05/31/2023, 3:32 PMJoel Denke
05/31/2023, 3:38 PMobject MyTheme {
val typography: MyTypography
@Composable
@ReadOnlyComposable
get() = LocalMyTypography.current
val colorTheme: MyColorTheme
@Composable
@ReadOnlyComposable
get() = LocalMyColorTheme.current
}
But I cant change the vals to being internal, as I cant then calling that code anymore.
This only happening when adding both pod shared and presentation pod at same time into PodFile.
Not sure why 😄Joel Denke
05/31/2023, 3:39 PMJoel Denke
05/31/2023, 3:39 PMOleksandr Karpovich [JB]
05/31/2023, 3:41 PMJoel Denke
05/31/2023, 3:45 PMOleksandr Karpovich [JB]
05/31/2023, 3:49 PMJoel Denke
05/31/2023, 3:51 PMJoel Denke
05/31/2023, 3:52 PMJoel Denke
05/31/2023, 3:53 PMOleksandr Karpovich [JB]
05/31/2023, 3:54 PMJoel Denke
05/31/2023, 3:55 PMJoel Denke
05/31/2023, 3:55 PMOleksandr Karpovich [JB]
05/31/2023, 3:55 PMJoel Denke
05/31/2023, 3:55 PMOleksandr Karpovich [JB]
05/31/2023, 3:56 PMJoel Denke
05/31/2023, 3:56 PMJoel Denke
05/31/2023, 3:59 PM