[resources] Add functions to retrieve bytes from drawable or font resources.#4651
Merged
[resources] Add functions to retrieve bytes from drawable or font resources.#4651
Conversation
igordmn
requested changes
Apr 18, 2024
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
...ts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt
Outdated
Show resolved
Hide resolved
47bd458 to
4c1bb1e
Compare
…e loading functions and function to get current compose environment
4c1bb1e to
cd26460
Compare
igordmn
reviewed
Apr 19, 2024
...sources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.kt
Outdated
Show resolved
Hide resolved
...nts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/FontResources.kt
Outdated
Show resolved
Hide resolved
| */ | ||
| @ExperimentalResourceApi | ||
| suspend fun getFontResourceBytes( | ||
| environment: ResourceEnvironment = getResourceEnvironment(), |
Collaborator
There was a problem hiding this comment.
Having environment on the first place forces users to use resource name explicitly. Was this the intention?
I don't have a strong opinion here. On one hand, it is better for users to make a conscience choice to use the system environment, on the other hand it is verbose.
Member
Author
There was a problem hiding this comment.
Yes, it was done to avoid parameters after a vararg in
suspend fun getString(
environment: ResourceEnvironment,
resource: StringResource,
vararg formatArgs: Any
): String
Collaborator
There was a problem hiding this comment.
In this case, I would suggest to do the same for the other functions - split them into 2:
@ExperimentalResourceApi
suspend fun getFontResourceBytes(
environment: ResourceEnvironment,
resource: FontResource
): ByteArray
@ExperimentalResourceApi
suspend fun getFontResourceBytes(
environment: ResourceEnvironment,
): ByteArray = getFontResourceBytes(getSystemResourceEnvironment(), resource)
Otherwise we can't write getDrawableResourceBytes(Res.drawable.title), only getDrawableResourceBytes(resource = Res.drawable.title)
...nts/resources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/FontResources.kt
Show resolved
Hide resolved
...ources/library/src/commonMain/kotlin/org/jetbrains/compose/resources/StringArrayResources.kt
Show resolved
Hide resolved
Because resources are not supported on native message targets.
igordmn
reviewed
Apr 23, 2024
...urces/library/src/commonMain/kotlin/org/jetbrains/compose/resources/PluralStringResources.kt
Show resolved
Hide resolved
igordmn
reviewed
Apr 23, 2024
...urces/library/src/commonMain/kotlin/org/jetbrains/compose/resources/PluralStringResources.kt
Show resolved
Hide resolved
igordmn
approved these changes
Apr 23, 2024
MatkovIvan
suggested changes
Apr 23, 2024
| val theme: ThemeQualifier, | ||
| val density: DensityQualifier | ||
| @ExperimentalResourceApi | ||
| data class ResourceEnvironment internal constructor( |
Contributor
There was a problem hiding this comment.
MatkovIvan
approved these changes
Apr 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented two new experimental functions:
fixes #4360