-
Notifications
You must be signed in to change notification settings - Fork 92
Closed
Labels
enhancementNew feature or requestNew feature or requestplatform: iOSThis affects iOSThis affects iOS
Milestone
Description
Proposal
In iOS, adding a custom font requires updating UIAppFonts
in Info.plist
https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app
Looks like it's not supported right now so I propose an additional fonts
property under platform in the Manifest (app.json)
{
"ios": {
"fonts": [
"EuclidCircularB-Regular.ttf"
"EuclidCircularB-Bold.ttf",
]
}
}
Implementation Details
The reading of manifest on iOS could be similar to app icons
react-native-test-app/ios/test_app.rb
Line 242 in 511d368
generate_assets_catalog!(project_root, target_platform, destination) |
CFPropertyList
(subdep of current gems). Here's some code (thanks CodePilot), tested in example and it works.
require("cfpropertylist")
# ...
def set_fonts_in_plist!(project_root, target_platform, destination)
fonts = platform_config('fonts', project_root, target_platform)
return if fonts.nil? || fonts.empty?
info_plist = File.join(destination, 'ReactTestApp', 'Info.plist')
plist = CFPropertyList::List.new(file: info_plist)
data = CFPropertyList.native_types(plist.value)
data['UIAppFonts'] = []
fonts.each do |font|
data['UIAppFonts'] << File.basename(font)
end
plist.value = CFPropertyList.guess(data)
File.write(info_plist, plist.to_str(CFPropertyList::List::FORMAT_XML))
end
# ...
generate_assets_catalog!(project_root, target_platform, destination)
set_fonts_in_plist!(project_root, target_platform, destination)
Also worth adding the font files automatically to resources, otherwise they need to be duplicated in resources.ios[]
.
Code of Conduct
- I agree to follow this project's Code of Conduct
tido64 and kelsetkarlsander
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestplatform: iOSThis affects iOSThis affects iOS