diff --git a/tests/app/file-name-resolver-tests/file-name-resolver-tests.ts b/tests/app/file-name-resolver-tests/file-name-resolver-tests.ts index 26c59637d..19cce8011 100644 --- a/tests/app/file-name-resolver-tests/file-name-resolver-tests.ts +++ b/tests/app/file-name-resolver-tests/file-name-resolver-tests.ts @@ -208,7 +208,7 @@ export function test_findFileMatch_with_multiple_matches_loads_by_priority() { } function testTemplate(candidates: Array, context: resolver.PlatformContext, expected: string) { - var result = resolver.findFileMatch("test", ".xml", candidates, context); + var result = resolver._findFileMatch("test", ".xml", candidates, context); TKUnit.assertEqual(result, expected, "File path"); } diff --git a/tns-core-modules/application/application-common.ts b/tns-core-modules/application/application-common.ts index 55cff0386..653085232 100644 --- a/tns-core-modules/application/application-common.ts +++ b/tns-core-modules/application/application-common.ts @@ -7,6 +7,7 @@ import * as fileSystemModule from "file-system"; import * as styleScopeModule from "ui/styling/style-scope"; import * as fileResolverModule from "file-system/file-name-resolver"; import * as builderModule from "ui/builder"; +import * as platformModule from "platform"; import "../bundle-entry-points"; var builder: typeof builderModule; @@ -16,6 +17,20 @@ function ensureBuilder() { } } +var platform: typeof platformModule; +function ensurePlatform() { + if (!platform) { + platform = require("platform"); + } +} + +var fileNameResolver: typeof fileResolverModule; +function ensureFileNameResolver() { + if (!fileNameResolver) { + fileNameResolver = require("file-system/file-name-resolver"); + } +} + var styleScope: typeof styleScopeModule = undefined; var events = new observable.Observable(); @@ -112,10 +127,10 @@ export function __onLiveSync() { } try { - var fileResolver: typeof fileResolverModule = require("file-system/file-name-resolver"); + ensureFileNameResolver(); // Clear file resolver cache to respect newly added files. - fileResolver.clearCache(); + fileNameResolver.clearCache(); // Reload app.css in case it was changed. loadCss(); @@ -134,4 +149,12 @@ export function __onLiveSyncCore() { // Reload current page. frame.reloadPage(); } -global.__onLiveSyncCore = __onLiveSyncCore; \ No newline at end of file +global.__onLiveSyncCore = __onLiveSyncCore; + +export function _onOrientationChanged(){ + ensurePlatform(); + platform.screen.mainScreen._invalidate(); + + ensureFileNameResolver(); + fileNameResolver._invalidateResolverInstance(); +} \ No newline at end of file diff --git a/tns-core-modules/application/application.android.ts b/tns-core-modules/application/application.android.ts index bc3e7c776..7b49ef493 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -148,6 +148,7 @@ function initComponentCallbacks() { break; } + appModule._onOrientationChanged(); typedExports.notify({ eventName: typedExports.orientationChangedEvent, android: androidApp.nativeApp, diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index bc6aae751..d1609c8b2 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -205,6 +205,7 @@ class IOSApplication implements definition.iOSApplication { break; } + common._onOrientationChanged(); typedExports.notify({ eventName: typedExports.orientationChangedEvent, ios: this, diff --git a/tns-core-modules/file-system/file-name-resolver.d.ts b/tns-core-modules/file-system/file-name-resolver.d.ts index 5b18d44e1..96fd30827 100644 --- a/tns-core-modules/file-system/file-name-resolver.d.ts +++ b/tns-core-modules/file-system/file-name-resolver.d.ts @@ -17,9 +17,4 @@ declare module "file-system/file-name-resolver" { export function resolveFileName(path: string, ext: string): string; export function clearCache(): void; - - //@private - export function findFileMatch(path: string, ext: string, candidates: Array, context: PlatformContext): string - //@endprivate - } \ No newline at end of file diff --git a/tns-core-modules/file-system/file-name-resolver.ts b/tns-core-modules/file-system/file-name-resolver.ts index 1f7ca0e7e..05ee0b5ad 100644 --- a/tns-core-modules/file-system/file-name-resolver.ts +++ b/tns-core-modules/file-system/file-name-resolver.ts @@ -3,7 +3,11 @@ import fs = require("file-system"); import types = require("utils/types"); import trace = require("trace"); import platform = require("platform"); -import * as appModule from "application"; + +declare module "file-system/file-name-resolver" { + export function _findFileMatch(path: string, ext: string, candidates: Array, context: PlatformContext): string + export function _invalidateResolverInstance(): void; +} var MIN_WH: string = "minWH"; var MIN_W: string = "minW"; @@ -75,7 +79,7 @@ var minHeightQualifier: QualifierSpec = { } } -var paltformQualifier: QualifierSpec = { +var platformQualifier: QualifierSpec = { isMatch: function (value: string): boolean { return value === "android" || value === "ios"; @@ -104,7 +108,7 @@ var supportedQualifiers: Array = [ minWidthQualifier, minHeightQualifier, orientationQualifier, - paltformQualifier + platformQualifier ]; export class FileNameResolver implements definition.FileNameResolver { @@ -136,7 +140,7 @@ export class FileNameResolver implements definition.FileNameResolver { ext = "." + ext; var candidates = this.getFileCandidatesFromFolder(path, ext); - result = findFileMatch(path, ext, candidates, this._context); + result = _findFileMatch(path, ext, candidates, this._context); if (trace.enabled) { trace.write("Resolved file name for \"" + path + ext + "\" result: " + (result ? result : "no match found"), trace.categories.Navigation); @@ -171,7 +175,7 @@ export class FileNameResolver implements definition.FileNameResolver { } } -export function findFileMatch(path: string, ext: string, candidates: Array, context: definition.PlatformContext): string { +export function _findFileMatch(path: string, ext: string, candidates: Array, context: definition.PlatformContext): string { var bestValue = -1 var result: string = null; @@ -226,18 +230,9 @@ function checkQualifier(value: string, context: definition.PlatformContext) { return -1; } -var appEventAttached: boolean = false; var resolverInstance: FileNameResolver; export function resolveFileName(path: string, ext: string): string { - if (!appEventAttached) { - var app: typeof appModule = require("application"); - app.on(app.orientationChangedEvent, (data) => { - resolverInstance = undefined; - }); - appEventAttached = true; - } - if (!resolverInstance) { resolverInstance = new FileNameResolver({ width: platform.screen.mainScreen.widthDIPs, @@ -254,4 +249,8 @@ export function clearCache(): void { if (resolverInstance) { resolverInstance.clearCache(); } +} + +export function _invalidateResolverInstance(): void { + resolverInstance = undefined; } \ No newline at end of file diff --git a/tns-core-modules/platform/platform.android.ts b/tns-core-modules/platform/platform.android.ts index 0d26ef187..24502134c 100644 --- a/tns-core-modules/platform/platform.android.ts +++ b/tns-core-modules/platform/platform.android.ts @@ -3,6 +3,12 @@ import definition = require("platform"); import utils = require("utils/utils"); import * as enumsModule from "ui/enums"; +declare module "platform" { + export interface ScreenMetrics { + _invalidate(): void; + } +} + const MIN_TABLET_PIXELS = 600; export module platformNames { @@ -103,6 +109,11 @@ class Device implements definition.Device { class MainScreen implements definition.ScreenMetrics { private _metrics: android.util.DisplayMetrics; + + public _invalidate(): void { + this._metrics = null; + } + private get metrics(): android.util.DisplayMetrics { if (!this._metrics) { this._metrics = new android.util.DisplayMetrics(); diff --git a/tns-core-modules/platform/platform.ios.ts b/tns-core-modules/platform/platform.ios.ts index c2f4e5bfa..00246cdd4 100644 --- a/tns-core-modules/platform/platform.ios.ts +++ b/tns-core-modules/platform/platform.ios.ts @@ -98,6 +98,11 @@ class Device implements definition.Device { class MainScreen implements definition.ScreenMetrics { private _screen: UIScreen; + + _invalidate(){ + // + } + private get screen(): UIScreen { if (!this._screen) { this._screen = utils.ios.getter(UIScreen, UIScreen.mainScreen); diff --git a/tns-core-modules/ui/frame/frame-common.ts b/tns-core-modules/ui/frame/frame-common.ts index f7102d90b..351fadc36 100644 --- a/tns-core-modules/ui/frame/frame-common.ts +++ b/tns-core-modules/ui/frame/frame-common.ts @@ -122,6 +122,7 @@ function pageFromBuilder(moduleNamePath: string, moduleExports: any): Page { // Possible XML file path. var fileName = resolveFileName(moduleNamePath, "xml"); + if (fileName) { if (trace.enabled) { trace.write("Loading XML file: " + fileName, trace.categories.Navigation); @@ -136,6 +137,11 @@ function pageFromBuilder(moduleNamePath: string, moduleExports: any): Page { } } + // Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311 + // if (page && fileName === `${moduleNamePath}.port.xml` || fileName === `${moduleNamePath}.land.xml`){ + // page["isBiOrientational"] = true; + // } + return page; } @@ -210,6 +216,27 @@ export class Frame extends CustomLayoutView implements definition.Frame { } } + // Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311 + // private _subscribedToOrientationChangedEvent = false; + // private _onOrientationChanged(){ + // if (!this._currentEntry){ + // return; + // } + + // let currentPage = this._currentEntry.resolvedPage; + // let currentNavigationEntry = this._currentEntry.entry; + // if (currentPage["isBiOrientational"] && currentNavigationEntry.moduleName) { + // if (this.canGoBack()){ + // this.goBack(); + // } + // else { + // currentNavigationEntry.backstackVisible = false; + // } + // // Re-navigate to the same page so the other (.port or .land) xml is loaded. + // this.navigate(currentNavigationEntry); + // } + // } + public navigate(param: any) { if (trace.enabled) { trace.write(`NAVIGATE`, trace.categories.Navigation); @@ -218,6 +245,16 @@ export class Frame extends CustomLayoutView implements definition.Frame { var entry = buildEntryFromArgs(param); var page = resolvePageFromEntry(entry); + // Attempts to implement https://github.com/NativeScript/NativeScript/issues/1311 + // if (page["isBiOrientational"] && entry.moduleName && !this._subscribedToOrientationChangedEvent){ + // this._subscribedToOrientationChangedEvent = true; + // let app = require("application"); + // if (trace.enabled) { + // trace.write(`${this} subscribed to orientationChangedEvent.`, trace.categories.Navigation); + // } + // app.on(app.orientationChangedEvent, (data) => this._onOrientationChanged()); + // } + this._pushInFrameStack(); var backstackEntry: definition.BackstackEntry = {