Browse Source

[resources] Fix readResourceBytes function on Android if font is located under qualified directory (#4512)

Fix the problem when users try to read a font bytes under a qualified
directory.
pull/4482/head
Konstantin 8 months ago committed by GitHub
parent
commit
6f3eb08488
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt

2
components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt

@ -10,7 +10,7 @@ actual suspend fun readResourceBytes(path: String): ByteArray {
val classLoader = Thread.currentThread().contextClassLoader ?: AndroidResourceReader.javaClass.classLoader
val resource = classLoader.getResourceAsStream(path) ?: run {
//try to find a font in the android assets
if (File(path).parentFile?.name.orEmpty() == "font") {
if (File(path).parentFile?.name.orEmpty().startsWith("font")) {
classLoader.getResourceAsStream("assets/$path")
} else null
} ?: throw MissingResourceException(path)

Loading…
Cancel
Save