Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export function test_findFileMatch_with_multiple_matches_loads_by_priority() {
}

function testTemplate(candidates: Array<string>, 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");
}

Expand Down
29 changes: 26 additions & 3 deletions tns-core-modules/application/application-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -134,4 +149,12 @@ export function __onLiveSyncCore() {
// Reload current page.
frame.reloadPage();
}
global.__onLiveSyncCore = __onLiveSyncCore;
global.__onLiveSyncCore = __onLiveSyncCore;

export function _onOrientationChanged(){
ensurePlatform();
platform.screen.mainScreen._invalidate();

ensureFileNameResolver();
fileNameResolver._invalidateResolverInstance();
}
1 change: 1 addition & 0 deletions tns-core-modules/application/application.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function initComponentCallbacks() {
break;
}

appModule._onOrientationChanged();
typedExports.notify(<definition.OrientationChangedEventData>{
eventName: typedExports.orientationChangedEvent,
android: androidApp.nativeApp,
Expand Down
1 change: 1 addition & 0 deletions tns-core-modules/application/application.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class IOSApplication implements definition.iOSApplication {
break;
}

common._onOrientationChanged();
typedExports.notify(<definition.OrientationChangedEventData>{
eventName: typedExports.orientationChangedEvent,
ios: this,
Expand Down
5 changes: 0 additions & 5 deletions tns-core-modules/file-system/file-name-resolver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, context: PlatformContext): string
//@endprivate

}
27 changes: 13 additions & 14 deletions tns-core-modules/file-system/file-name-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, context: PlatformContext): string
export function _invalidateResolverInstance(): void;
}

var MIN_WH: string = "minWH";
var MIN_W: string = "minW";
Expand Down Expand Up @@ -75,7 +79,7 @@ var minHeightQualifier: QualifierSpec = {
}
}

var paltformQualifier: QualifierSpec = {
var platformQualifier: QualifierSpec = {
isMatch: function (value: string): boolean {
return value === "android" ||
value === "ios";
Expand Down Expand Up @@ -104,7 +108,7 @@ var supportedQualifiers: Array<QualifierSpec> = [
minWidthQualifier,
minHeightQualifier,
orientationQualifier,
paltformQualifier
platformQualifier
];

export class FileNameResolver implements definition.FileNameResolver {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -171,7 +175,7 @@ export class FileNameResolver implements definition.FileNameResolver {
}
}

export function findFileMatch(path: string, ext: string, candidates: Array<string>, context: definition.PlatformContext): string {
export function _findFileMatch(path: string, ext: string, candidates: Array<string>, context: definition.PlatformContext): string {
var bestValue = -1
var result: string = null;

Expand Down Expand Up @@ -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,
Expand All @@ -254,4 +249,8 @@ export function clearCache(): void {
if (resolverInstance) {
resolverInstance.clearCache();
}
}

export function _invalidateResolverInstance(): void {
resolverInstance = undefined;
}
11 changes: 11 additions & 0 deletions tns-core-modules/platform/platform.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions tns-core-modules/platform/platform.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions tns-core-modules/ui/frame/frame-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down