From 2a94532865529a9b1eb0719f2b06c4170516fca7 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Tue, 26 Jul 2016 13:48:03 +0300 Subject: [PATCH] Fix iOS font registration when bundling scripts. Use fs.knownFolders to get the app dir --- tns-core-modules/ui/styling/font.ios.ts | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tns-core-modules/ui/styling/font.ios.ts b/tns-core-modules/ui/styling/font.ios.ts index ad3cbaaa9..dd3544448 100644 --- a/tns-core-modules/ui/styling/font.ios.ts +++ b/tns-core-modules/ui/styling/font.ios.ts @@ -315,24 +315,28 @@ export module ios { } } -function registerCustomFonts() { - var fontsFolderPath = fs.path.join(__dirname.substring(0, __dirname.indexOf("/tns_modules")), "fonts"); - if (fs.Folder.exists(fontsFolderPath)) { - var fontsFolder = fs.Folder.fromPath(fontsFolderPath); - var onEachEntityFunc = function (fileEntity: fs.FileSystemEntity): boolean { - if (fs.Folder.exists(fs.path.join(fontsFolderPath, fileEntity.name))) { - return true; - } +function registerFontsInFolder(fontsFolderPath) { + const fontsFolder = fs.Folder.fromPath(fontsFolderPath); - if (fileEntity instanceof fs.File && - ((fileEntity).extension === ".ttf" || (fileEntity).extension === ".otf")) { - ios.registerFont(fileEntity.name); - } + fontsFolder.eachEntity((fileEntity: fs.FileSystemEntity) => { + if (fs.Folder.exists(fs.path.join(fontsFolderPath, fileEntity.name))) { return true; } - fontsFolder.eachEntity(onEachEntityFunc); + if (fileEntity instanceof fs.File && + ((fileEntity).extension === ".ttf" || (fileEntity).extension === ".otf")) { + ios.registerFont(fileEntity.name); + } + return true; + }); +} + +function registerCustomFonts() { + const appDir = fs.knownFolders.currentApp().path + const fontsDir = fs.path.join(appDir, "fonts"); + if (fs.Folder.exists(fontsDir)) { + registerFontsInFolder(fontsDir); } } -registerCustomFonts(); \ No newline at end of file +registerCustomFonts();