-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make ResourceReader a public API #5334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ResourceReader a public API #5334
Conversation
...ces/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt
Show resolved
Hide resolved
...ces/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt
Show resolved
Hide resolved
e4f6326
to
e8d66a6
Compare
...ces/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt
Show resolved
Hide resolved
...rces/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/CustomClassloaderTest.kt
Outdated
Show resolved
Hide resolved
When you open the ResourceReader API to public it means you finalize a format of the internal strings serialization format:
that is why I haven't been ready to do that. The format was invented on the go and I haven't think to stabilize it yet. One of the problem with these offset and size: CMP-5039 Overriding string resources causes crashes or inelligible strings |
We could annotate |
bbf9835
to
d69a6b4
Compare
...rces/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/CustomClassloaderTest.kt
Show resolved
Hide resolved
...s/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceReader.ios.kt
Outdated
Show resolved
Hide resolved
...nts/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/ResourceReader.js.kt
Outdated
Show resolved
Hide resolved
...sources/library/src/macosMain/kotlin/org/jetbrains/compose/resources/ResourceReader.macos.kt
Outdated
Show resolved
Hide resolved
...urces/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceReader.wasmJs.kt
Outdated
Show resolved
Hide resolved
...ces/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt
Outdated
Show resolved
Hide resolved
...esources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestResourceReader.kt
Outdated
Show resolved
Hide resolved
...ces/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt
Outdated
Show resolved
Hide resolved
...s/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceReader.ios.kt
Outdated
Show resolved
Hide resolved
@lamba92 you marked all the "shouldn't this be private" comments as resolved without addressing them nor replying. I cannot unresolve them myself, but they are not resolved at all. |
Sorry, I forgot to send the comment. The whole point of this MR is to expose @Composable
fun WithCustomResourceReader(reader: ResourceLoader, content: @Composable () -> Unit) {
CompositionLocalProvider(LocalResourceReader provides loader, content)
}
...
val reader = JvmResourceReader(this::class.java.classloader)
setContent {
WithCustomResourceReader(reader) {
...
}
} Given that the JVM implementation is public, I do not see why the default ones for the other platforms should not be as well. |
I can see why you'd want the JVM one to be public, but making others public is a bad idea for two reasons:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the comments, LGTM. @terrakok should perform the main review
...ces/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt
Outdated
Show resolved
Hide resolved
) : ResourceReader { | ||
|
||
companion object { | ||
val DEFAULT = JvmResourceReader() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making a top-level val DefaultJvmResourceReader
to be consistent with the other targets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also changed other platform implementations to be object
s. What do you mean exactly?
internal expect fun getPlatformResourceReader(): ResourceReader | ||
|
||
internal val DefaultResourceReader = getPlatformResourceReader() | ||
expect fun getDefaultResourceReader(): ResourceReader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making val DefaultResourceReader
to be consistent with the platform implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also changed other platform implementations to be object
s. What do you mean exactly?
132e8c3
to
8cf1eb7
Compare
I added |
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceReader.kt
Outdated
Show resolved
Hide resolved
...esources/library/src/commonTest/kotlin/org/jetbrains/compose/resources/TestResourceReader.kt
Outdated
Show resolved
Hide resolved
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceReader.kt
Show resolved
Hide resolved
...ces/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt
Outdated
Show resolved
Hide resolved
...s/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceReader.ios.kt
Show resolved
Hide resolved
1cb579c
to
e0f882a
Compare
e0f882a
to
9c1571d
Compare
...urces/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceReader.wasmJs.kt
Show resolved
Hide resolved
9c1571d
to
1739345
Compare
1739345
to
b91d0f6
Compare
b91d0f6
to
bf20c32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see you deleted the lazyness of test reader on web platforms.
Please, make only the JVM resource reader class public.
...ces/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt
Outdated
Show resolved
Hide resolved
@ExperimentalResourceApi | ||
internal actual fun getPlatformResourceReader(): ResourceReader = | ||
JvmResourceReader.Default | ||
|
||
@ExperimentalResourceApi | ||
class JvmResourceReader( | ||
private val classLoader: ClassLoader = JvmResourceReader::class.java.classLoader | ||
) : ResourceReader { | ||
|
||
companion object { | ||
val Default = JvmResourceReader() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is better
@ExperimentalResourceApi
internal actual fun getPlatformResourceReader(): ResourceReader = JvmResourceReader()
@ExperimentalResourceApi
class JvmResourceReader(
private val classLoader: ClassLoader = JvmResourceReader::class.java.classLoader
) : ResourceReader {
//no companion object
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. I see the difference now. then make
companion object {
internal val Default = JvmResourceReader()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Kotlin all object
s are initialized on their first symbol invokation. As such, a top level object is lazy by default. The lazy
has been designed for inlining lazyness in a function or a class property.
Please, make only the JVM resource reader class public.
On it
Make ResourceReader implementations public This change makes `ResourceReader` and its platform-specific implementations public. This allows users to provide custom implementations, for example, to load resources from a custom ClassLoader on JVM. A new test (`CustomClassloaderTest`) is added to verify that resources can be loaded from a custom ClassLoader. Additionally, some internal resource readers have been refactored from anonymous objects to regular objects for better organization and potential future reuse.
Make ResourceReader implementations public This change makes `ResourceReader` and its platform-specific implementations public. This allows users to provide custom implementations, for example, to load resources from a custom ClassLoader on JVM. A new test (`CustomClassloaderTest`) is added to verify that resources can be loaded from a custom ClassLoader. Additionally, some internal resource readers have been refactored from anonymous objects to regular objects for better organization and potential future reuse.
be999b1
to
1a662db
Compare
❤️ |
Describe proposed changes and the issue being fixed Fixes [CMP-8134](https://youtrack.jetbrains.com/issue/CMP-8134/Switch-the-ClassLoader-used-by-ResourceReader) ## Testing - [x] Add Test to **desktopTest** SourceSet - (Optional) This should be tested by QA ## Release Notes ### Features - Resources - Added `JvmResourceReader` API and made `LocalResourceReader` public to allow providing a custom classloader for desktop target
Describe proposed changes and the issue being fixed
Fixes CMP-8134
Testing
Release Notes
Features - Resources
JvmResourceReader
API and madeLocalResourceReader
public to allow providing a custom classloader for desktop target