-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[resources] Add functions to retrieve bytes from drawable or font resources. #4651
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70c00f6
[resources] Add functions to retrieve bytes from drawable or font res…
terrakok cd26460
[resources] Add optional environment parameter to non-compose resourc…
terrakok 052066f
[resources] Add experimental getSystemResourceEnvironment function.
terrakok 6930446
[resources] Update compose multiplatform version.
terrakok a98d479
[resources] Mark ResourceEnvironment as experimental and add a sample…
terrakok 031359e
[resources] Delete macos native target from the demo app.
terrakok 5d857dd
[resources] Mark new API as experimental.
terrakok 450b7e7
[resources] Don't provide default environment for read bytes functions.
terrakok c70b909
[resources] Update javadoc.
terrakok b1edfbd
[resources] Don't use data class in public API.
terrakok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
1 change: 0 additions & 1 deletion
1
components/resources/demo/shared/src/macosMain/composeResources/files/platform-text.txt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
components/resources/demo/shared/src/macosMain/kotlin/main.macos.kt
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,12 @@ import androidx.compose.runtime.* | |
| import androidx.compose.ui.platform.LocalDensity | ||
| import androidx.compose.ui.text.intl.Locale | ||
|
|
||
| internal data class ResourceEnvironment( | ||
| val language: LanguageQualifier, | ||
| val region: RegionQualifier, | ||
| val theme: ThemeQualifier, | ||
| val density: DensityQualifier | ||
| @ExperimentalResourceApi | ||
| data class ResourceEnvironment internal constructor( | ||
igordmn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| internal val language: LanguageQualifier, | ||
| internal val region: RegionQualifier, | ||
| internal val theme: ThemeQualifier, | ||
| internal val density: DensityQualifier | ||
| ) | ||
|
|
||
| internal interface ComposeEnvironment { | ||
|
|
@@ -39,14 +40,32 @@ internal val DefaultComposeEnvironment = object : ComposeEnvironment { | |
| //ComposeEnvironment provider will be overridden for tests | ||
| internal val LocalComposeEnvironment = staticCompositionLocalOf { DefaultComposeEnvironment } | ||
|
|
||
| /** | ||
| * Returns an instance of [ResourceEnvironment]. | ||
| * | ||
| * The [ResourceEnvironment] class represents the environment for resources. | ||
| * | ||
| * @return An instance of [ResourceEnvironment] representing the current environment. | ||
| */ | ||
| @ExperimentalResourceApi | ||
| @Composable | ||
| fun rememberResourceEnvironment(): ResourceEnvironment { | ||
| val composeEnvironment = LocalComposeEnvironment.current | ||
| return composeEnvironment.rememberEnvironment() | ||
| } | ||
|
|
||
| internal expect fun getSystemEnvironment(): ResourceEnvironment | ||
|
|
||
| //the function reference will be overridden for tests | ||
| //@TestOnly | ||
| internal var getResourceEnvironment = ::getSystemEnvironment | ||
|
|
||
| /** | ||
| * Provides the resource environment for non-composable access to string resources. | ||
| * Provides the resource environment for non-composable access to resources. | ||
| * It is an expensive operation! Don't use it in composable functions with no cache! | ||
| */ | ||
| internal var getResourceEnvironment = ::getSystemEnvironment | ||
| @ExperimentalResourceApi | ||
| fun getSystemResourceEnvironment(): ResourceEnvironment = getResourceEnvironment() | ||
|
|
||
| @OptIn(InternalResourceApi::class) | ||
| internal fun Resource.getResourceItemByEnvironment(environment: ResourceEnvironment): ResourceItem { | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.