mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor(HMR): apply changes in application styles at runtime
This commit is contained in:
@@ -32,7 +32,14 @@ export function hasLaunched(): boolean {
|
||||
|
||||
export { Observable };
|
||||
|
||||
import { UnhandledErrorEventData, iOSApplication, AndroidApplication, CssChangedEventData, LoadAppCSSEventData } from ".";
|
||||
import {
|
||||
AndroidApplication,
|
||||
CssChangedEventData,
|
||||
getRootView,
|
||||
iOSApplication,
|
||||
LoadAppCSSEventData,
|
||||
UnhandledErrorEventData
|
||||
} from "./application";
|
||||
|
||||
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
||||
|
||||
@@ -73,8 +80,19 @@ export function setApplication(instance: iOSApplication | AndroidApplication): v
|
||||
export function livesync(context?: HmrContext) {
|
||||
events.notify(<EventData>{ eventName: "livesync", object: app });
|
||||
const liveSyncCore = global.__onLiveSyncCore;
|
||||
if (liveSyncCore) {
|
||||
liveSyncCore(context);
|
||||
let reapplyAppCss = false
|
||||
|
||||
if (context) {
|
||||
const fullFileName = getCssFileName();
|
||||
const fileName = fullFileName.substring(0, fullFileName.lastIndexOf(".") + 1);
|
||||
const extensions = ["css", "scss"];
|
||||
reapplyAppCss = extensions.some(ext => context.module === fileName.concat(ext));
|
||||
}
|
||||
|
||||
if (reapplyAppCss) {
|
||||
getRootView()._onCssStateChange();
|
||||
} else if (liveSyncCore) {
|
||||
liveSyncCore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ export * from "./application-common";
|
||||
import { createViewFromEntry } from "../ui/builder";
|
||||
import { ios as iosView, View } from "../ui/core/view";
|
||||
import { Frame, NavigationEntry } from "../ui/frame";
|
||||
import { loadCss } from "../ui/styling/style-scope";
|
||||
import * as utils from "../utils/utils";
|
||||
import { profile, level as profilingLevel, Level } from "../profiling";
|
||||
|
||||
@@ -162,7 +161,7 @@ class IOSApplication implements IOSApplicationDefinition {
|
||||
this.setWindowContent(args.root);
|
||||
} else {
|
||||
this._window = UIApplication.sharedApplication.delegate.window;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@profile
|
||||
@@ -226,21 +225,10 @@ class IOSApplication implements IOSApplicationDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
public _onLivesync(context?: HmrContext): void {
|
||||
let executeLivesync = true;
|
||||
// HMR has context, livesync does not
|
||||
if (context) {
|
||||
if (context.module === getCssFileName()) {
|
||||
loadCss(context.module);
|
||||
this._rootView._onCssStateChange();
|
||||
executeLivesync = false;
|
||||
}
|
||||
}
|
||||
if (executeLivesync) {
|
||||
// If view can't handle livesync set window controller.
|
||||
if (!this._rootView._onLivesync()) {
|
||||
this.setWindowContent();
|
||||
}
|
||||
public _onLivesync(): void {
|
||||
// If view can't handle livesync set window controller.
|
||||
if (!this._rootView._onLivesync()) {
|
||||
this.setWindowContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,8 +264,8 @@ exports.ios = iosApp;
|
||||
setApplication(iosApp);
|
||||
|
||||
// attach on global, so it can be overwritten in NativeScript Angular
|
||||
(<any>global).__onLiveSyncCore = function __onLiveSyncCore(context?: HmrContext) {
|
||||
iosApp._onLivesync(context);
|
||||
(<any>global).__onLiveSyncCore = function () {
|
||||
iosApp._onLivesync();
|
||||
}
|
||||
|
||||
let mainEntry: NavigationEntry;
|
||||
@@ -391,4 +379,4 @@ global.__onLiveSync = function __onLiveSync(context?: HmrContext) {
|
||||
}
|
||||
|
||||
livesync(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user