Browse Source

Add `setResourceReaderAndroidContext` to configure Android context for resource reading (#5434)

Fixes https://youtrack.jetbrains.com/issue/CMP-6676

## Release Notes
### Features - Resources
- Add `setResourceReaderAndroidContext` to configure Android context in
cases when a provider initialization is not available.
pull/5435/head
Konstantin 3 months ago committed by GitHub
parent
commit
f420cb8c3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/AndroidContextProvider.kt

13
components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/AndroidContextProvider.kt

@ -38,6 +38,19 @@ fun PreviewContextConfigurationEffect() { @@ -38,6 +38,19 @@ fun PreviewContextConfigurationEffect() {
}
}
/**
* Sets the android context to be used for resource read functions in cases
* when `org.jetbrains.compose.components.resources.resources.AndroidContextProvider` cannot be initialized.
*
* Be careful when using this function! The context will be retained for the whole application lifetime.
*
* See https://youtrack.jetbrains.com/issue/CMP-6676 for more details.
*/
@ExperimentalResourceApi
fun setResourceReaderAndroidContext(context: Context) {
AndroidContextProvider.ANDROID_CONTEXT = context
}
//https://andretietz.com/2017/09/06/autoinitialise-android-library/
internal class AndroidContextProvider : ContentProvider() {
companion object {

Loading…
Cancel
Save