[TIMOB-23914] Hyperloop - iOS: UIImage.imageNamed returns null
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Resolved |
Resolution | Duplicate |
Resolution Date | 2018-08-13T18:56:44.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Hyperloop, iOS, Tooling |
Labels | n/a |
Reporter | Brian García |
Assignee | Unknown |
Created | 2016-09-15T15:01:09.000+0000 |
Updated | 2018-08-13T18:56:44.000+0000 |
Description
requesting an image placed in assets/images with
UIImage.imageNamed
returns null when the expected result is a reference to the image.
Hello, Can you try putting the image in app/assets/iphone (Alloy) and Resources/iphone (Titanium classic)?. Referance: http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Hyperloop_Programming_Guide-section-46253491_iOSHyperloopProgrammingGuide-Functionpointers. Thanks.
already did it and the result is the same. EDIT: The images must be placed in src folder and the src folder needs to be required in appc.js otherwise the files in src are ignored. anyways it would be great to use images placed in assets/images to avoid duplicating files
Hello, Please provide a sample code that you are testing. Thanks.
[~bgarcia] So placing them in /src works? Can you provide a workaround here, so people can use that one until we adjust the core with it? Thanks!
Yes! just place any image in /src folder and make sure that you are requiring the src folder in appc.js with any framework. It can be in the form
Thank you! The effort of this ticket should be that the Hyperloop CLI is able to search assets (not only images) in: - Resources/ (for classic projects) - app/assets/ (for Alloy projects) - src/ (for Hyperloop-projects - without manual framework linking) I guess the CLI for that should be pretty straight-forward. I would actually say that people should only place assets in the first two directories and only place frameworks in src/. And since we already copy the assets of the first two directories, the real problem is that the names of the images in the asset catalogs are hashed, so calling them with the "real name" causes problems. [~cbarber] any idea here? For now, I would provide a new util-method in [hyperloop-utilities](https://github.com/appcelerator/hyperloop-utilities) but that can't be a long-term solution.
I agree, don't put images or other non-source files in
src
. Put them inResources
orapp/assets
. Asset catalogs are only enabled if<use-app-thinning>
is true in the<ios>
section of thetiapp.xml
. It is true by default. The generated asset catalog image set's name is just the sha1 of the image's filename including extension without any\@2x
/\@3x
or~iphone
/~ipad
tokens. It should be pretty easy to figure out. Look at the iOS build for clues: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/cli/commands/_build.js#L5269.For everyone stumbling across this issue, there is a temporary workaround as [~cbarber] mentioned above. Generate the SHA-1 hash of the image, e.g.
Create the image in Hyperloop
You could use a simple JS object map to avoid using the hashes throughout your code and access them with descriptive keys.
Btw, this will be resolved in SDK 8.0.0 as part of [this PR](https://github.com/appcelerator/titanium_mobile/pull/10239). Cheers!