Guys, I’m trying to understand how the new resourc...
# compose
a
Guys, I’m trying to understand how the new resources API works (1.6.0-beta01). I have a couple of questions. 1. Is it possible to create subfolders in
composeResources
(e.g.
drawable/foo/bar/baz.png
)? 2. Is there any API for programmatically changing the region/language/other resource qualifiers? I want to provide the way for users to change the app settings.
j
1. I think it has to follow https://developer.android.com/guide/topics/resources/providing-resources structure. Its same concept as in Android resources. 2. From what I seen in code no, but I could be wrong. However curious how you mean change app settings? You will be able to change locale and such as normally can in an app / OS level.
πŸ‘ 1
a
Oh, I see. I'll make a couple of issues then. 2. I don't think I can change locale per app on the desktop (using OS settings). Apps on desktop often provide ways to change locale/interface size in the app itself. I hope to be able to do that using the new resources API.
Thank you!
j
@Azim Muradov Oh I see its desktop. Hmm yeah not sure if desktop can use the Jvm Locale things or not, I guess depends which desktop OS? Maybe can override the Locale local composition somehow, not expert in how they bridge those compositions per platform. I mostly know iOS vs Android. But interesting learn more about desktop as well.
Also resources can be stored however you want, its more if you want Res generated class and all platforms to work I think follow drawable structure required. So also depends if using lets say Android vs Desktop, or only using Desktop compose. Also can use resource composable with raw path and not using qualifiers at all already. its all about which features want to have πŸ™‚
a
@Joel Denke I use Desktop + Web (WASM), that's the reason I use experimental multiplatform solutions for resources πŸ˜…. It worked fine on 1.5.11, but with the new changes in the API I lost some of the provided flexibility.
j
Hehe yeah I lost the same features myself in Android and iOS. Feels like it went to far to similar as Android resources, which is not agnostic enough to work across all platforms. Need to have custom adjustable resources, like I need to have video and audio files not working in new resource structure, so I had to implement my own resource solution similar to Jetbrains one at the moment. But you should be able to use resource("path") I think and using the byte array and convert however you want in each platform. For now trying a hybride with help from @Kashismails where overloading parts of the jetbrains resources to use 1.5.11 version for iOS but using 1.6.0 beta01 for iOS in combination with my own solution πŸ™‚
a
Thanks! I'll try to use resource("path"), maybe it will be enough for now. I think you can try to put your audios and videos into
files
. And then process them as byte arrays. That way you would be able to use the new API. Although, I'm not familiar with iOS development, maybe I'm wrong.
j
Yeah my problem was for video the libraries I use for iOS vs Android using urls and not byte arrays πŸ˜„ So would then need to clone the entire byte array into a new file and save it, instead of get the original path. So I asked Jetbrains to add this into their existing APIs, hopefully added in future πŸ™‚ Sometimes need bytes, sometimes need NSurl in iOS, sometimes need url in web to file source, sometimes need Uri in Android etc. Dont know what desktop using in general πŸ˜› But using byteArray you can clone Jetbrains extensions of convert them from that into images in compose for desktop πŸ™‚
a
Hahaha, I see 😁
j
Created my own PlatformResource class hybride support all variants, including Jetbrains one, so I can select which resource and variant I need per case. Some samples here https://github.com/JetBrains/compose-multiplatform/blob/master/components/resource[…]onMain/kotlin/org/jetbrains/compose/resources/ImageResources.kt how to deal with images πŸ™‚
πŸ”₯ 1
https://github.com/JetBrains/compose-multiplatform/blob/master/components/resource[…]/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt From this code it looks like you can override Locale, by setup Locale.setLocale method if need that btw. But looks like their LocalResourceEnvironment internal at the moment.
a
I know, already found (and described in the issue) πŸ™‚ They basically need to make it and some of the data classes public, so you can provide environment locally.
πŸ‘ 1