From 88f5c9a7fd9cf251668aa8b4b0521572d67fd863 Mon Sep 17 00:00:00 2001 From: Andreww8xx8 Date: Fri, 13 Mar 2015 13:52:17 +0300 Subject: [PATCH] Ability to use different templates for iOS and Android added --- apps/editable-text-demo/app.ts | 2 +- apps/platform-specific-template/app.ts | 3 +++ .../main-page.android.xml | 5 +++++ apps/platform-specific-template/main-page.ios.xml | 5 +++++ apps/platform-specific-template/main-page.ts | 1 + apps/platform-specific-template/package.json | 2 ++ ui/frame/frame-common.ts | 15 +++++++++++++-- 7 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 apps/platform-specific-template/app.ts create mode 100644 apps/platform-specific-template/main-page.android.xml create mode 100644 apps/platform-specific-template/main-page.ios.xml create mode 100644 apps/platform-specific-template/main-page.ts create mode 100644 apps/platform-specific-template/package.json diff --git a/apps/editable-text-demo/app.ts b/apps/editable-text-demo/app.ts index 0f172a73b..83670f56b 100644 --- a/apps/editable-text-demo/app.ts +++ b/apps/editable-text-demo/app.ts @@ -1,3 +1,3 @@ import application = require("application"); application.mainModule = "app/main-page"; -application.start(); \ No newline at end of file +application.start(); diff --git a/apps/platform-specific-template/app.ts b/apps/platform-specific-template/app.ts new file mode 100644 index 000000000..83670f56b --- /dev/null +++ b/apps/platform-specific-template/app.ts @@ -0,0 +1,3 @@ +import application = require("application"); +application.mainModule = "app/main-page"; +application.start(); diff --git a/apps/platform-specific-template/main-page.android.xml b/apps/platform-specific-template/main-page.android.xml new file mode 100644 index 000000000..a4508325e --- /dev/null +++ b/apps/platform-specific-template/main-page.android.xml @@ -0,0 +1,5 @@ + + + + diff --git a/apps/platform-specific-template/main-page.ios.xml b/apps/platform-specific-template/main-page.ios.xml new file mode 100644 index 000000000..c3be93a20 --- /dev/null +++ b/apps/platform-specific-template/main-page.ios.xml @@ -0,0 +1,5 @@ + + + + diff --git a/apps/platform-specific-template/main-page.ts b/apps/platform-specific-template/main-page.ts new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/apps/platform-specific-template/main-page.ts @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/platform-specific-template/package.json b/apps/platform-specific-template/package.json new file mode 100644 index 000000000..cdfd44208 --- /dev/null +++ b/apps/platform-specific-template/package.json @@ -0,0 +1,2 @@ +{ "name" : "platform-specific-template", + "main" : "app.js" } diff --git a/ui/frame/frame-common.ts b/ui/frame/frame-common.ts index 84749370d..eacee85aa 100644 --- a/ui/frame/frame-common.ts +++ b/ui/frame/frame-common.ts @@ -6,6 +6,7 @@ import trace = require("trace"); import builder = require("ui/builder"); import fs = require("file-system"); import utils = require("utils/utils"); +import platform = require("platform"); var frameStack: Array = []; @@ -39,7 +40,7 @@ function resolvePageFromEntry(entry: definition.NavigationEntry): pages.Page { } } else if (entry.moduleName) { - // Current app full path. + // Current app full path. var currentAppPath = fs.knownFolders.currentApp().path; //Full path of the module = current app full path + module name. var moduleNamePath = fs.path.join(currentAppPath, entry.moduleName); @@ -67,12 +68,22 @@ function resolvePageFromEntry(entry: definition.NavigationEntry): pages.Page { return page; } +function resolvePlatformPath(path, ext) { + var platformName = platform.device.os.toLowerCase(); + var platformPath = [path, platformName, ext].join("."); + if (fs.File.exists(platformPath)) { + return platformPath; + } + + return [path, ext].join("."); +} + function pageFromBuilder(moduleNamePath: string, moduleName: string, moduleExports: any): pages.Page { var page: pages.Page; var element: view.View; // Possible XML file path. - var fileName = moduleNamePath + ".xml"; + var fileName = resolvePlatformPath(moduleNamePath, "xml"); if (fs.File.exists(fileName)) { trace.write("Loading XML file: " + fileName, trace.categories.Navigation);