Hello :wave: how can I read drawable in compose-i...
# compose-ios
s
Hello đź‘‹ how can I read drawable in compose-ios
a
Use
painterResource
m
moko-resource
s
@ayodele
painterResource
doesn't take drawable resource ID
m
f.e.:
s
I figured out you can also add it directly to the Xcode project. If it gets recognized as a resource it will be added to the IPA. If you imported
implementation(compose.components.resources)
you can use it this way:
Copy code
Image(
    painter = painterResource("blubb.xml"),
    contentDescription = null
)
I'm sure that moko-resource is a great library to handle that, but I always try to keep my dependencies to a minimum. Therefore a Gradle task will copy my resources.
s
Thank you all ~
@Magdalena Tsolaki I follow the documentation but strings are not generating, any idea?
Copy code
public expect object MR {
  public object strings : ResourceContainer<StringResource>

  public object plurals : ResourceContainer<PluralsResource>

  public object images : ResourceContainer<ImageResource>

  public object fonts : ResourceContainer<FontResource>

  public object files : ResourceContainer<FileResource>

  public object colors : ResourceContainer<ColorResource>

  public object assets : ResourceContainer<AssetResource>
}
a
Hello @Stefan Oltmann , you shared a very nice idea for creating a gradle task yourself for copying image resources from common. I want to know if I just copy the files into ios directory, will it be sufficient? Or any other xcode command needs to be executed as well?
s
I did not write it yet since I was tasked with other priorities, but it could be possible that some kind of Xcode command is needed. If I copy it manually my project file changes. I planned to look up how the existing resource copying works for the cocoapods plugin. But maybe Jetbrains is faster with their solution and I don’t need that gradle task as a workaround.
a
Currently, Images are not found in iOS if I keep them in commonMain resources. I manually have to copy them to iOSMain as well in order to avoid runtime crash. Therefore, KMM or cocoapods don't do this for us (I am using multiplatform compose)
s
It indeed needs some configuration to work with CocoaPods: https://github.com/JetBrains/compose-multiplatform-ios-android-template/blob/29ce600cb86a23c343c56aed7b8a18fa00db40b4/shared/build.gradle.kts#L25 But you can manually copy it into your Xcode project and it will work. See my screenshot above.
a
Thank you yes, I am aware about this one, but again it also requires resources to be copied manually to iosMain.
s
Why do you need that?
a
App will crash otherwise on iOS. Resources are not copied if I keep them in CommonMain. Works fine on Android