Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23914] Hyperloop - iOS: UIImage.imageNamed returns null

GitHub Issuen/a
TypeBug
PriorityHigh
StatusResolved
ResolutionDuplicate
Resolution Date2018-08-13T18:56:44.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop, iOS, Tooling
Labelsn/a
ReporterBrian García
AssigneeUnknown
Created2016-09-15T15:01:09.000+0000
Updated2018-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.

Comments

  1. Sharif AbuDarda 2016-09-15

    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.
  2. Brian García 2016-09-15

    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
  3. Sharif AbuDarda 2016-09-16

    Hello, Please provide a sample code that you are testing. Thanks.
  4. Hans Knöchel 2016-09-16

    [~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!
  5. Brian García 2016-09-17

    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
       thirdparty : {
            'dummyFramework' : {
                source : ['src'],
                header : 'src',
                resource : 'src'
           }
       }
       
  6. Hans Knöchel 2016-09-18

    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.
  7. Chris Barber 2016-09-18

    I agree, don't put images or other non-source files in src. Put them in Resources or app/assets. Asset catalogs are only enabled if <use-app-thinning> is true in the <ios> section of the tiapp.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.
  8. Jan Vennemann 2018-08-13

    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.
       ~ ❱❱❱ echo -n "assets/images/tab1.png" | shasum
       f58b0d04f3ad524648680e9940fb4e77323cb9bb  -
       
    Create the image in Hyperloop
       const UIImage = require('UIKit/UIImage');
       const image = UIImage.imageNamed('f58b0d04f3ad524648680e9940fb4e77323cb9bb');
       
    You could use a simple JS object map to avoid using the hashes throughout your code and access them with descriptive keys.
  9. Hans Knöchel 2018-08-13

    Btw, this will be resolved in SDK 8.0.0 as part of [this PR](https://github.com/appcelerator/titanium_mobile/pull/10239). Cheers!

JSON Source