feat(HMR): apply changes in page styles at runtime when app root is a frame (#6857)

* feat(HMR): apply changes in page styles at runtime

* fix: livesync tests

* test: changeCssFile method

* refactor: address comments

Add a comment.
Update `let` to `const`.
Update `changesCssFile` test.

* test: add an assert
This commit is contained in:
Vasil Chimev
2019-02-14 14:03:13 +02:00
committed by GitHub
parent 8e9a13c705
commit 44b8acd79c
10 changed files with 120 additions and 59 deletions

View File

@@ -82,19 +82,23 @@ export function setApplication(instance: iOSApplication | AndroidApplication): v
export function livesync(rootView: View, context?: ModuleContext) {
events.notify(<EventData>{ eventName: "livesync", object: app });
const liveSyncCore = global.__onLiveSyncCore;
let reapplyAppCss = false;
let reapplyAppStyles = false;
let reapplyLocalStyles = false;
if (context) {
const fullFileName = getCssFileName();
const fileName = fullFileName.substring(0, fullFileName.lastIndexOf(".") + 1);
if (context && context.path) {
const extensions = ["css", "scss"];
reapplyAppCss = extensions.some(ext => context.path === fileName.concat(ext));
const appStylesFullFileName = getCssFileName();
const appStylesFileName = appStylesFullFileName.substring(0, appStylesFullFileName.lastIndexOf(".") + 1);
reapplyAppStyles = extensions.some(ext => context.path === appStylesFileName.concat(ext));
if (!reapplyAppStyles) {
reapplyLocalStyles = extensions.some(ext => context.path.endsWith(ext));
}
}
if (reapplyAppCss && rootView) {
if (reapplyAppStyles && rootView) {
rootView._onCssStateChange();
} else if (liveSyncCore) {
liveSyncCore();
reapplyLocalStyles ? liveSyncCore(context) : liveSyncCore();
}
}

View File

@@ -225,9 +225,9 @@ class IOSApplication implements IOSApplicationDefinition {
}
}
public _onLivesync(): void {
public _onLivesync(context?: ModuleContext): void {
// If view can't handle livesync set window controller.
if (this._rootView && !this._rootView._onLivesync()) {
if (this._rootView && !this._rootView._onLivesync(context)) {
this.setWindowContent();
}
}
@@ -264,8 +264,8 @@ exports.ios = iosApp;
setApplication(iosApp);
// attach on global, so it can be overwritten in NativeScript Angular
(<any>global).__onLiveSyncCore = function () {
iosApp._onLivesync();
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) {
iosApp._onLivesync(context);
}
let mainEntry: NavigationEntry;