Browse Source

[resources] Missing fixes with Classloader (#2490)

pull/2497/head
dima.avdeev 2 years ago committed by GitHub
parent
commit
0807d06e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt
  2. 3
      components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt

3
components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt

@ -13,7 +13,8 @@ actual fun resource(path: String): Resource = AndroidResourceImpl(path)
@ExperimentalResourceApi
private class AndroidResourceImpl(path: String) : AbstractResourceImpl(path) {
override suspend fun readBytes(): ByteArray {
val resource = (::AndroidResourceImpl.javaClass.classLoader).getResourceAsStream(path)
val classLoader = Thread.currentThread().contextClassLoader ?: (::AndroidResourceImpl.javaClass.classLoader)
val resource = classLoader.getResourceAsStream(path)
if (resource != null) {
return resource.readBytes()
} else {

3
components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt

@ -13,7 +13,8 @@ actual fun resource(path: String): Resource = DesktopResourceImpl(path)
@ExperimentalResourceApi
private class DesktopResourceImpl(path: String) : AbstractResourceImpl(path) {
override suspend fun readBytes(): ByteArray {
val resource = (::DesktopResourceImpl.javaClass.classLoader).getResourceAsStream(path)
val classLoader = Thread.currentThread().contextClassLoader ?: (::DesktopResourceImpl.javaClass.classLoader)
val resource = classLoader.getResourceAsStream(path)
if (resource != null) {
return resource.readBytes()
} else {

Loading…
Cancel
Save