From cfa37cfa28dac80576a9cbacd7f97f5d7fb18600 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 3 May 2019 13:26:37 +0300 Subject: [PATCH] fix-next(HMR): apply changes in page styles at runtime when app root is a frame --- tns-core-modules/ui/core/view/view-common.ts | 4 ++-- tns-core-modules/ui/core/view/view.d.ts | 6 +++++- tns-core-modules/ui/frame/frame.android.ts | 5 +++++ tns-core-modules/ui/frame/frame.ios.ts | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tns-core-modules/ui/core/view/view-common.ts b/tns-core-modules/ui/core/view/view-common.ts index a9c627a84..992f135c0 100644 --- a/tns-core-modules/ui/core/view/view-common.ts +++ b/tns-core-modules/ui/core/view/view-common.ts @@ -153,7 +153,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { if (context && context.type && context.path) { // Handle local styles if (context.type === ModuleType.style) { - return this.changeLocalStyles(context.path); + return this._changeLocalStyles(context.path); } // Handle module markup and script changes else { @@ -164,7 +164,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { return false; } - private changeLocalStyles(contextPath: string): boolean { + public _changeLocalStyles(contextPath: string): boolean { if (!this.changeStyles(this, contextPath)) { eachDescendant(this, (child: ViewBase) => { this.changeStyles(child, contextPath); diff --git a/tns-core-modules/ui/core/view/view.d.ts b/tns-core-modules/ui/core/view/view.d.ts index 1e4d7dcc2..f2be87694 100644 --- a/tns-core-modules/ui/core/view/view.d.ts +++ b/tns-core-modules/ui/core/view/view.d.ts @@ -474,7 +474,7 @@ export abstract class View extends ViewBase { /** * @deprecated use on() instead - * + * * @param type - Type of the gesture. * @param callback - A function that will be executed when gesture is received. * @param thisArg - An optional parameter which will be used as `this` context for callback execution. @@ -683,6 +683,10 @@ export abstract class View extends ViewBase { * @private */ _onLivesync(context?: { type: string, path: string }): boolean; + /** + * @private + */ + _changeLocalStyles(contextPath: string): boolean; /** * @private */ diff --git a/tns-core-modules/ui/frame/frame.android.ts b/tns-core-modules/ui/frame/frame.android.ts index 0192ec102..3f21d8b9a 100644 --- a/tns-core-modules/ui/frame/frame.android.ts +++ b/tns-core-modules/ui/frame/frame.android.ts @@ -349,6 +349,11 @@ export class Frame extends FrameBase { } if (context && context.type && context.path) { + // Handle local styls changes when app root is Frame + if (context.type === ModuleType.style) { + return this._changeLocalStyles(context.path); + } + // Set NavigationType.replace for HMR. this.navigationType = NavigationType.replace; const currentBackstackEntry = this._currentEntry; diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index d85cc5189..6bc3281aa 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -3,6 +3,7 @@ import { iOSFrame as iOSFrameDefinition, BackstackEntry, NavigationTransition } from "."; import { Page } from "../page"; +import { ModuleType } from "../../ui/core/view/view-common"; import { profile } from "../../profiling"; //Types. @@ -73,6 +74,11 @@ export class Frame extends FrameBase { } if (context && context.type && context.path) { + // Handle local styls changes when app root is Frame + if (context.type === ModuleType.style) { + return this._changeLocalStyles(context.path); + } + // Set NavigationType.replace for HMR. // When `viewDidAppear()` set to NavigationType.forward. this.navigationType = NavigationType.replace;