Merge pull request #1074 from NativeScript/feature/fix-livesync-css-not-refreshed

Reload app.css and clear file resolver cache on livesync.
This commit is contained in:
Alexander Vakrilov
2015-11-10 17:13:47 +02:00
5 changed files with 47 additions and 4 deletions

View File

@@ -50,8 +50,4 @@ export function loadCss() {
}
}
}
}
global.__onLiveSync = function () {
frame.reloadPage();
}

View File

@@ -4,6 +4,7 @@ import frame = require("ui/frame");
import types = require("utils/types");
import observable = require("data/observable");
import enums = require("ui/enums");
import fileResolverModule = require("file-system/file-name-resolver");
global.moduleMerge(appModule, exports);
@@ -71,6 +72,8 @@ var initEvents = function () {
return;
}
(<any>androidApp).paused = true;
if (activity === androidApp.foregroundActivity) {
if (exports.onSuspend) {
exports.onSuspend();
@@ -91,6 +94,8 @@ var initEvents = function () {
return;
}
(<any>androidApp).paused = false;
if (activity === androidApp.foregroundActivity) {
if (exports.onResume) {
exports.onResume();
@@ -347,3 +352,18 @@ function onConfigurationChanged(context: android.content.Context, intent: androi
});
}
}
global.__onLiveSync = function () {
if (exports.android && exports.android.paused) {
return;
}
// Clear file resolver cache to respect newly added files.
fileResolverModule.clearCache();
// Reload app.css in case it was changed.
appModule.loadCss();
// Reload current page.
frame.reloadPage();
}

View File

@@ -5,6 +5,7 @@ import view = require("ui/core/view");
import definition = require("application");
import enums = require("ui/enums");
import uiUtils = require("ui/utils");
import fileResolverModule = require("file-system/file-name-resolver");
global.moduleMerge(appModule, exports);
@@ -227,3 +228,18 @@ exports.start = function () {
throw new Error("iOS Application already started!");
}
}
global.__onLiveSync = function () {
if (!started) {
return;
}
// Clear file resolver cache to respect newly added files.
fileResolverModule.clearCache();
// Reload app.css in case it was changed.
appModule.loadCss();
// Reload current page.
frame.reloadPage();
}

View File

@@ -12,9 +12,11 @@ declare module "file-system/file-name-resolver" {
export class FileNameResolver {
constructor(context: PlatformContext);
resolveFileName(path: string, ext: string): string;
clearCache(): void;
}
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

View File

@@ -126,6 +126,10 @@ export class FileNameResolver implements definition.FileNameResolver {
return result;
}
public clearCache(): void {
this._cache = {};
}
private resolveFileNameImpl(path: string, ext: string): string {
var result: string = null;
path = fs.path.normalize(path);
@@ -239,3 +243,8 @@ export function resolveFileName(path: string, ext: string): string {
return resolverInstance.resolveFileName(path, ext);
}
export function clearCache(): void {
if (resolverInstance) {
resolverInstance.clearCache();
}
}