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

Incorrect file path for font assets on iOS

Open TheHeumanModean opened this issue 2 years ago • 3 comments

Context

used ignite boilerplate this potentially changes iOS folder structure

Steps to reproduce

  • added custom font to ./assets/fonts
|
|_ assets
|_|_ fonts
|_|_|_ font-name
|_|_|_|_ ttf-file-name.ttf
  • changed react-native.config.js
module.exports = {
  assets: ['./assets/fonts/'],
}
  • ran npx react-native-asset
  • android builds fine and fonts are correct
  • iOS fails build with No such file or directory found on each of my ttf files

Steps that I did to fix

  • in the file ios/projectName.xcodeproj/project.pgxproj under the /* Begin PBXFileReference section */ replaced every ../assets/fonts/font-name/ttf-file-name.ttf with an extra ../ to make ../../assets/fonts/font-name/ttf-file-name.ttf

before

197A7A355453429EBCF9A29A /* ttf-file-name.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ttf-file-name.ttf"; path = "../assets/fonts/font-name/ttf-file-name.ttf"; sourceTree = "<group>"; };

after

197A7A355453429EBCF9A29A /* ttf-file-name.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ttf-file-name.ttf"; path = "../../assets/fonts/font-name/ttf-file-name.ttf"; sourceTree = "<group>"; };

TheHeumanModean avatar Jan 06 '23 20:01 TheHeumanModean

I have same problem. App builds but fonts do not work in ios. When i apply this fix, build start to fail.

morwalz avatar Jan 29 '23 14:01 morwalz

Not sure what the problem is, happily merge whatever PR you do to fix this

unimonkiez avatar Feb 28 '23 09:02 unimonkiez

The problem here is that the cordova-node-xcode library's project.addResourceFile() is to add the resource as "Relative to Group" in Xcode, which is "<Project>/Resources".

I'm investigating if there is an option on addResourceFile() that can set it relative to the project. I'll have a PR with a potential solution for discussion shortly.

cayleyh avatar Jun 15 '23 17:06 cayleyh