Giter Club home page Giter Club logo

Comments (5)

alexzhirkevich avatar alexzhirkevich commented on August 22, 2024

The documentation does not specify at all how to access (common) resources on a iOS side of a Compose Multiplatform project.

🤯

image

UIImage.imageNamed(
    Res.getUri("drawable/logo.png")
        .substringAfter(NSBundle.mainBundle.resourcePath!!)
        .removePrefix("/")
)

image

UIImage.imageWithData(Res.readBytes("drawable/logo.png").toNsData())

@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
fun ByteArray.toNSData(): NSData = this.usePinned {
    NSData.create(bytes = it.addressOf(0), length = this.size.convert())
}

from compose-multiplatform.

kocheick avatar kocheick commented on August 22, 2024

Thanks for the quick reply and pointing this out !

I've tried the getUri, and when I do this

  ...
 val imagePath = Res.getUri("drawable/logo.png").substringAfter(NSBundle.mainBundle.resourcePath!!).removePrefix("/")

println(imagePath) // this output -> "composeResources/compose-resources/resources/drawable/logo.png"

the value of imagePath is exactly the same as in my above example ~ meaning it's pointing towards the correct path, however it's not loading/find the resource in there

Does Res.getUri display anything when you try it ?

from compose-multiplatform.

kropp avatar kropp commented on August 22, 2024

@terrakok please take a look

from compose-multiplatform.

terrakok avatar terrakok commented on August 22, 2024

@kocheick How do you integrate your kotlin code to the iOS app? Are you sure the resources are presented in the final app? If not, try to generate a new project and do the same

from compose-multiplatform.

kocheick avatar kocheick commented on August 22, 2024

@terrakok
Closing this, all is actually well with Compose.
As I was trying to make a sample project to demonstrate this issue, I came to find out the reason my resources were not loading in the app was due to corrupted files ~ i had copied the logo image from one project to another within Intellij-idea and somehow the copy became a corrupted file (couldn't open it within the ide but no issue opening the original logo within the ide).
I ended up making a copy within Finder from the original project to the new project and now Compose displays it as it should.

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.