Skip to content

Commit f420cb8

Browse files
authored
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.
1 parent 5e1fed6 commit f420cb8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ fun PreviewContextConfigurationEffect() {
3838
}
3939
}
4040

41+
/**
42+
* Sets the android context to be used for resource read functions in cases
43+
* when `org.jetbrains.compose.components.resources.resources.AndroidContextProvider` cannot be initialized.
44+
*
45+
* Be careful when using this function! The context will be retained for the whole application lifetime.
46+
*
47+
* See https://youtrack.jetbrains.com/issue/CMP-6676 for more details.
48+
*/
49+
@ExperimentalResourceApi
50+
fun setResourceReaderAndroidContext(context: Context) {
51+
AndroidContextProvider.ANDROID_CONTEXT = context
52+
}
53+
4154
//https://andretietz.com/2017/09/06/autoinitialise-android-library/
4255
internal class AndroidContextProvider : ContentProvider() {
4356
companion object {

0 commit comments

Comments
 (0)