react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Use asset catalog for ios images

Open janicduplessis opened this issue 5 years ago • 37 comments

Summary

Use an asset catalog for images on iOS. See related PR in the CLI for the code that generates it https://github.com/react-native-community/cli/pull/1290.

Changelog:

[iOS] [Added] - Use asset catalog for ios images

Test Plan

See https://github.com/react-native-community/cli/pull/1290

Test on RN Tester

  1. Add to root package.json and yarn install
  "resolutions": {
    "@react-native-community/cli-plugin-metro": "janicduplessis/react-native-cli#react-native-community-cli-plugin-metro-v9.1.3-test.0-gitpkg"
  },
  1. PRODUCTION=1 yarn setup-ios-jsc in packages/rn-tester

  2. In Xcode, product -> scheme -> edit scheme -> change Build Configuration to Release.

  3. Build and check that local images are working. image

janicduplessis avatar Oct 07 '20 21:10 janicduplessis

Warnings
:warning: :lock: package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

Generated by :no_entry_sign: dangerJS against 1c7e31ba2ab80466cf837700b1c3d91f382a0412

pull-bot avatar Oct 07 '20 21:10 pull-bot

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 950ea915bee6b3b30107c04bd34990fb390c7268 Branch: main

analysis-bot avatar Oct 07 '20 21:10 analysis-bot

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,895,039 +1
android hermes armeabi-v7a 7,943,587 +2
android hermes x86 9,292,924 +1
android hermes x86_64 9,194,442 -2
android jsc arm64-v8a 9,482,023 +0
android jsc armeabi-v7a 8,423,567 +0
android jsc x86 9,466,043 -1
android jsc x86_64 9,780,275 +2

Base commit: c27e9e647781774b0469fa4f2ca6969784084230 Branch: main

analysis-bot avatar Oct 07 '20 21:10 analysis-bot

@janicduplessis I haven't dived deep into assets stuff on the CLI side and here, but maybe you have a better overview on this. Now that assets logic is scoped under @react-native/assets package, maybe we could reuse it on the CLI side? We should strive to reuse everything that's possible to avoid these weird syncing situations (this is not the first time).

thymikee avatar Nov 18 '20 12:11 thymikee

@thymikee This already uses the shared code in the assets package and updates it (just rename a method since it is now used on iOS too).

janicduplessis avatar Jan 04 '22 22:01 janicduplessis

@sota000 Any interest on landing this? I've been using this in my fork for a long time and is stable.

janicduplessis avatar Jan 04 '22 22:01 janicduplessis

It would be great to have a status on this one, there's an outstanding PR in the CLI too.

grabbou avatar Feb 15 '22 12:02 grabbou

One think I'd guess would be fixing the conflicts, but yeah also would be great to get some internal 👍/👎 if it's even worth

kelset avatar Feb 15 '22 14:02 kelset

@janicduplessis can we rebase + fix the conflicts here?

cortinico avatar Oct 04 '22 09:10 cortinico

Ok I rebased this and tested again in RN tester. I added instructions on how to do so in the Test Plan. It does require the CLI patched with https://github.com/react-native-community/cli/pull/1290 to work.

I think the main part that is tricky with this is if the app template is not properly updated or for some reason an older version of the cli is used it will break. For the old cli version case it is actually not that bad since the build will error because of invalid parameter --asset-catalog-dest. If the template project is not properly configured then assets won't show in release mode only.

I think it is still fine to move forward, but might want to make sure to document the change to make sure templates are updated properly. The main 2 things that need updating is to create the RNAssets.xcassets catalog and to reorder build scripts so that JS bundle is built before Copy Bundle Resources. For new projects and automated updates that should be fine, but might not be obvious for someone updating manually.

janicduplessis avatar Oct 04 '22 18:10 janicduplessis

/rebase

cipolleschi avatar Oct 05 '22 09:10 cipolleschi

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 05 '22 09:10 facebook-github-bot

Weird, this PR makes the template tests fail... Basically, the CLI is not able to create a RN app... Is it expected because it requires https://github.com/react-native-community/cli/pull/1290 ?

cipolleschi avatar Oct 05 '22 15:10 cipolleschi

Oh I see the problem, the template yarn install fails because of error Couldn't find any versions for "@react-native/assets" that matches "1.1.0". Not sure what would be best to handle updating the @react-native/assets package. It is basically just renaming a function since we use it on iOS too now.

janicduplessis avatar Oct 05 '22 15:10 janicduplessis

We might also have build issue later for ios release build since it does require the cli patch

janicduplessis avatar Oct 05 '22 15:10 janicduplessis

@cortinico @cipolleschi Template tests are all passing except the ios release ones, with error error: unknown option '--asset-catalog-dest', which is expected since it doesn’t include the updated cli. Maybe the next step would be to get the cli PR merged and published.

janicduplessis avatar Oct 06 '22 05:10 janicduplessis

@cortinico @cipolleschi Template tests are all passing except the ios release ones, with error error: unknown option '--asset-catalog-dest', which is expected since it doesn’t include the updated cli. Maybe the next step would be to get the cli PR merged and published.

Sounds like a plan 👍

cortinico avatar Oct 06 '22 10:10 cortinico

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 07 '22 11:10 facebook-github-bot

@cortinico Cli is updated and template tests are passing now, I don’t think other test failures are related, but will double check.

janicduplessis avatar Oct 17 '22 20:10 janicduplessis

/rebase

cipolleschi avatar Oct 18 '22 11:10 cipolleschi

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 18 '22 12:10 facebook-github-bot

Hi there, the analyze-code job fails due to some linting problems in the JS side. Could you have a look at them and fix them, please?

Screenshot 2022-10-18 at 16 44 51

cipolleschi avatar Oct 18 '22 15:10 cipolleschi

PR build artifact for 3dc67c896cc23451cf0c558b0e82d575c7e47326 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 21 '22 20:10 pull-bot

PR build artifact for 3dc67c896cc23451cf0c558b0e82d575c7e47326 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 21 '22 20:10 pull-bot

@javache Thanks for reviewing this. I've reimplemented the logic to convert from the file url to the asset catalog name in objc and made it so it falls back to using the current bundle url logic if the image doesn't exist in the catalog. It will also log a warning.

I've tested that the Image example works with and without an asset catalog (by not passing the asset catalog arg to the CLI). This also makes sure old way to include assets work too and doesn't log a warning.

janicduplessis avatar Oct 22 '22 01:10 janicduplessis

PR build artifact for 64f025a331cdb1e0fe9a7a9c065ba7677e48d336 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 01:10 pull-bot

PR build artifact for 64f025a331cdb1e0fe9a7a9c065ba7677e48d336 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 01:10 pull-bot

PR build artifact for 6a1a87adf01a6715271b38b1a126cf8260e91d30 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 02:10 pull-bot

PR build artifact for 6a1a87adf01a6715271b38b1a126cf8260e91d30 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 02:10 pull-bot

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Nov 10 '22 13:11 facebook-github-bot