Comments (5)
The documentation does not specify at all how to access (common) resources on a iOS side of a Compose Multiplatform project.
🤯
UIImage.imageNamed(
Res.getUri("drawable/logo.png")
.substringAfter(NSBundle.mainBundle.resourcePath!!)
.removePrefix("/")
)
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.
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.
@terrakok please take a look
from compose-multiplatform.
@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.
@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)
- [1.7.0-alpha01] GraphicsLayer do not seems to like being drawn multiple times HOT 3
- MacOS Notarize App with Native Library Failed Error 65 HOT 4
- [1.7.0-alpha01] Moving after initiating a click cancels it HOT 2
- Preview in commonMain? HOT 2
- [1.7.0-alpha01] Cannot change attributes of dependency configuration ':debugFrameworkIosArm64' after it has been resolved HOT 9
- I have an issue with a common ViewModel and navigation in my Compose Multiplatform application HOT 3
- Ios crash while using textMeasurer.measure inside Dispatchers.Default HOT 17
- CompositionLocalProvider related RuntimeError: illegal cast HOT 7
- Compose navigation crash v2.8.0-alpha08 (UnsatisfiedLinkError) HOT 5
- Support common `org.jetbrains.compose.ui.tooling.preview.Preview` in IDEA and Android Studio HOT 13
- ShadowJar Executable HOT 2
- Error: self-signed certificate in certificate chain HOT 5
- Improved window sizing API (Windows) HOT 3
- iOS Keyboard Broken with `readOnly` will show/hide in loop HOT 13
- iOS: ModalBottomSheet can't ignore safeArea HOT 2
- Unable to run tests using Multiplatform Resources HOT 2
- Make AnnotatedString.Companion.fromHtml available to multiplatform HOT 3
- [WASM] Custom Font Text flickering from tofu to the actual text with the right font HOT 3
- Previewing fails with AssertionError: Data is too big HOT 1
- Important: please use YouTrack for bugs and feature requests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-multiplatform.