| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6095779 commit 42a1491
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,11 +70,11 @@ export function setApplication(instance: iOSApplication | AndroidApplication): v | |||
| 70 | 70 | app = instance; | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | - export function livesync() { | ||
| 73 | + export function livesync(context?: HmrContext) { | ||
| 74 | 74 | events.notify(<EventData>{ eventName: "livesync", object: app }); | |
| 75 | 75 | const liveSyncCore = global.__onLiveSyncCore; | |
| 76 | 76 | if (liveSyncCore) { | |
| 77 | - liveSyncCore(); | ||
| 77 | + liveSyncCore(context); | ||
| 78 | 78 | } | |
| 79 | 79 | } | |
| 80 | 80 | ||
@@ -92,7 +92,7 @@ export function loadAppCss(): void { | |||
| 92 | 92 | events.notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: app, cssFile: getCssFileName() }); | |
| 93 | 93 | } catch (e) { | |
| 94 | 94 | throw new Error(`The file ${getCssFileName()} couldn't be loaded! ` + | |
| 95 | - `You may need to register it inside ./app/vendor.ts.`); | ||
| 95 | + `You may need to register it inside ./app/vendor.ts.`); | ||
| 96 | 96 | } | |
| 97 | 97 | } | |
| 98 | 98 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -212,12 +212,12 @@ export function getNativeApplication(): android.app.Application { | |||
| 212 | 212 | return nativeApp; | |
| 213 | 213 | } | |
| 214 | 214 | ||
| 215 | - global.__onLiveSync = function () { | ||
| 215 | + global.__onLiveSync = function __onLiveSync(context?: HmrContext) { | ||
| 216 | 216 | if (androidApp && androidApp.paused) { | |
| 217 | 217 | return; | |
| 218 | 218 | } | |
| 219 | 219 | ||
| 220 | - livesync(); | ||
| 220 | + livesync(context); | ||
| 221 | 221 | }; | |
| 222 | 222 | ||
| 223 | 223 | function initLifecycleCallbacks() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ export * from "./application-common"; | |||
| 18 | 18 | import { createViewFromEntry } from "../ui/builder"; | |
| 19 | 19 | import { ios as iosView, View } from "../ui/core/view"; | |
| 20 | 20 | import { Frame, NavigationEntry } from "../ui/frame"; | |
| 21 | + import { loadCss } from "../ui/styling/style-scope"; | ||
| 21 | 22 | import * as utils from "../utils/utils"; | |
| 22 | 23 | import { profile, level as profilingLevel, Level } from "../profiling"; | |
| 23 | 24 | ||
@@ -225,10 +226,21 @@ class IOSApplication implements IOSApplicationDefinition { | |||
| 225 | 226 | } | |
| 226 | 227 | } | |
| 227 | 228 | ||
| 228 | - public _onLivesync(): void { | ||
| 229 | - // If view can't handle livesync set window controller. | ||
| 230 | - if (!this._rootView._onLivesync()) { | ||
| 231 | - this.setWindowContent(); | ||
| 229 | + public _onLivesync(context?: HmrContext): void { | ||
| 230 | + let executeLivesync = true; | ||
| 231 | + // HMR has context, livesync does not | ||
| 232 | + if (context) { | ||
| 233 | + if (context.module === getCssFileName()) { | ||
| 234 | + loadCss(context.module); | ||
| 235 | + this._rootView._onCssStateChange(); | ||
| 236 | + executeLivesync = false; | ||
| 237 | + } | ||
| 238 | + } | ||
| 239 | + if (executeLivesync) { | ||
| 240 | + // If view can't handle livesync set window controller. | ||
| 241 | + if (!this._rootView._onLivesync()) { | ||
| 242 | + this.setWindowContent(); | ||
| 243 | + } | ||
| 232 | 244 | } | |
| 233 | 245 | } | |
| 234 | 246 | ||
@@ -264,8 +276,8 @@ exports.ios = iosApp; | |||
| 264 | 276 | setApplication(iosApp); | |
| 265 | 277 | ||
| 266 | 278 | // attach on global, so it can be overwritten in NativeScript Angular | |
| 267 | - (<any>global).__onLiveSyncCore = function () { | ||
| 268 | - iosApp._onLivesync(); | ||
| 279 | + (<any>global).__onLiveSyncCore = function __onLiveSyncCore(context?: HmrContext) { | ||
| 280 | + iosApp._onLivesync(context); | ||
| 269 | 281 | } | |
| 270 | 282 | ||
| 271 | 283 | let mainEntry: NavigationEntry; | |
@@ -373,10 +385,10 @@ function setViewControllerView(view: View): void { | |||
| 373 | 385 | } | |
| 374 | 386 | } | |
| 375 | 387 | ||
| 376 | - global.__onLiveSync = function () { | ||
| 388 | + global.__onLiveSync = function __onLiveSync(context?: HmrContext) { | ||
| 377 | 389 | if (!started) { | |
| 378 | 390 | return; | |
| 379 | 391 | } | |
| 380 | 392 | ||
| 381 | - livesync(); | ||
| 393 | + livesync(context); | ||
| 382 | 394 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,8 +51,8 @@ declare namespace NodeJS { | |||
| 51 | 51 | __native?: any; | |
| 52 | 52 | __inspector?: any; | |
| 53 | 53 | __extends: any; | |
| 54 | - __onLiveSync: () => void; | ||
| 55 | - __onLiveSyncCore: () => void; | ||
| 54 | + __onLiveSync: (context?: { type: string, module: string }) => void; | ||
| 55 | + __onLiveSyncCore: (context?: { type: string, module: string }) => void; | ||
| 56 | 56 | __onUncaughtError: (error: NativeScriptError) => void; | |
| 57 | 57 | TNS_WEBPACK?: boolean; | |
| 58 | 58 | __requireOverride?: (name: string, dir: string) => any; | |
@@ -64,6 +64,27 @@ declare function clearTimeout(timeoutId: number): void; | |||
| 64 | 64 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; | |
| 65 | 65 | declare function clearInterval(intervalId: number): void; | |
| 66 | 66 | ||
| 67 | + declare enum HmrType { | ||
| 68 | + markup = "markup", | ||
| 69 | + script = "script", | ||
| 70 | + style = "style" | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * Define a context for Hot Module Replacement. | ||
| 75 | + */ | ||
| 76 | + interface HmrContext { | ||
| 77 | + /** | ||
| 78 | + * The type of module for replacement. | ||
| 79 | + */ | ||
| 80 | + type: HmrType; | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * The module for replacement. | ||
| 84 | + */ | ||
| 85 | + module: string; | ||
| 86 | + } | ||
| 87 | + | ||
| 67 | 88 | /** | |
| 68 | 89 | * An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code. | |
| 69 | 90 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ import { | |||
| 17 | 17 | _updateTransitions, _reverseTransitions, _clearEntry, _clearFragment, AnimationType | |
| 18 | 18 | } from "./fragment.transitions"; | |
| 19 | 19 | ||
| 20 | + import { loadCss } from "../styling/style-scope"; | ||
| 20 | 21 | import { profile } from "../../profiling"; | |
| 21 | 22 | ||
| 22 | 23 | // TODO: Remove this and get it from global to decouple builder for angular | |
@@ -82,13 +83,24 @@ function getAttachListener(): android.view.View.OnAttachStateChangeListener { | |||
| 82 | 83 | return attachStateChangeListener; | |
| 83 | 84 | } | |
| 84 | 85 | ||
| 85 | - export function reloadPage(): void { | ||
| 86 | + export function reloadPage(context?: HmrContext): void { | ||
| 86 | 87 | const activity = application.android.foregroundActivity; | |
| 87 | 88 | const callbacks: AndroidActivityCallbacks = activity[CALLBACKS]; | |
| 88 | 89 | const rootView: View = callbacks.getRootView(); | |
| 89 | 90 | ||
| 90 | - if (!rootView || !rootView._onLivesync()) { | ||
| 91 | - callbacks.resetActivityContent(activity); | ||
| 91 | + let executeLivesync = true; | ||
| 92 | + // HMR has context, livesync does not | ||
| 93 | + if (context) { | ||
| 94 | + if (context.module === application.getCssFileName()) { | ||
| 95 | + loadCss(context.module); | ||
| 96 | + rootView._onCssStateChange(); | ||
| 97 | + executeLivesync = false; | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + if (executeLivesync) { | ||
| 101 | + if (!rootView || !rootView._onLivesync()) { | ||
| 102 | + callbacks.resetActivityContent(activity); | ||
| 103 | + } | ||
| 92 | 104 | } | |
| 93 | 105 | } | |
| 94 | 106 | ||
@@ -469,19 +481,19 @@ export class Frame extends FrameBase { | |||
| 469 | 481 | switch (this.actionBarVisibility) { | |
| 470 | 482 | case "never": | |
| 471 | 483 | return false; | |
| 472 | - | ||
| 484 | + | ||
| 473 | 485 | case "always": | |
| 474 | 486 | return true; | |
| 475 | - | ||
| 487 | + | ||
| 476 | 488 | default: | |
| 477 | 489 | if (page.actionBarHidden !== undefined) { | |
| 478 | 490 | return !page.actionBarHidden; | |
| 479 | 491 | } | |
| 480 | - | ||
| 492 | + | ||
| 481 | 493 | if (this._android && this._android.showActionBar !== undefined) { | |
| 482 | 494 | return this._android.showActionBar; | |
| 483 | 495 | } | |
| 484 | - | ||
| 496 | + | ||
| 485 | 497 | return true; | |
| 486 | 498 | } | |
| 487 | 499 | } | |
@@ -846,14 +858,14 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { | |||
| 846 | 858 | // parent while its supposed parent believes it properly removed its children; in order to "force" the child to | |
| 847 | 859 | // lose its parent we temporarily add it to the parent, and then remove it (addViewInLayout doesn't trigger layout pass) | |
| 848 | 860 | const nativeView = page.nativeViewProtected; | |
| 849 | - if (nativeView != null) { | ||
| 850 | - const parentView = nativeView.getParent(); | ||
| 861 | + if (nativeView != null) { | ||
| 862 | + const parentView = nativeView.getParent(); | ||
| 851 | 863 | if (parentView instanceof android.view.ViewGroup) { | |
| 852 | 864 | if (parentView.getChildCount() === 0) { | |
| 853 | 865 | parentView.addViewInLayout(nativeView, -1, new org.nativescript.widgets.CommonLayoutParams()); | |
| 854 | 866 | } | |
| 855 | 867 | ||
| 856 | - parentView.removeView(nativeView); | ||
| 868 | + parentView.removeView(nativeView); | ||
| 857 | 869 | } | |
| 858 | 870 | } | |
| 859 | 871 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,17 +17,17 @@ export class PageBase extends ContentView implements PageDefinition { | |||
| 17 | 17 | public static navigatedToEvent = "navigatedTo"; | |
| 18 | 18 | public static navigatingFromEvent = "navigatingFrom"; | |
| 19 | 19 | public static navigatedFromEvent = "navigatedFrom"; | |
| 20 | - | ||
| 20 | + | ||
| 21 | 21 | private _navigationContext: any; | |
| 22 | 22 | private _actionBar: ActionBar; | |
| 23 | 23 | ||
| 24 | 24 | public _frame: Frame; | |
| 25 | - | ||
| 25 | + | ||
| 26 | 26 | public actionBarHidden: boolean; | |
| 27 | 27 | public enableSwipeBackNavigation: boolean; | |
| 28 | 28 | public backgroundSpanUnderStatusBar: boolean; | |
| 29 | 29 | public hasActionBar: boolean; | |
| 30 | - | ||
| 30 | + | ||
| 31 | 31 | get navigationContext(): any { | |
| 32 | 32 | return this._navigationContext; | |
| 33 | 33 | } | |
@@ -89,7 +89,7 @@ export class PageBase extends ContentView implements PageDefinition { | |||
| 89 | 89 | const frame = this.parent; | |
| 90 | 90 | return frame instanceof Frame ? frame : undefined; | |
| 91 | 91 | } | |
| 92 | - | ||
| 92 | + | ||
| 93 | 93 | private createNavigatedData(eventName: string, isBackNavigation: boolean): NavigatedData { | |
| 94 | 94 | return { | |
| 95 | 95 | eventName: eventName, | |
@@ -103,6 +103,10 @@ export class PageBase extends ContentView implements PageDefinition { | |||
| 103 | 103 | public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any) { | |
| 104 | 104 | this._navigationContext = context; | |
| 105 | 105 | ||
| 106 | + if (!this._cssState.isSelectorsLatestVersionApplied()) { | ||
| 107 | + this._onCssStateChange(); | ||
| 108 | + } | ||
| 109 | + | ||
| 106 | 110 | //https://github.com/NativeScript/NativeScript/issues/731 | |
| 107 | 111 | if (!isBackNavigation && bindingContext !== undefined && bindingContext !== null) { | |
| 108 | 112 | this.bindingContext = bindingContext; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,11 @@ export class CssState { | |||
| 19 | 19 | * Gets the static selectors that match the view and the dynamic selectors that may potentially match the view. | |
| 20 | 20 | */ | |
| 21 | 21 | public changeMap: ChangeMap<ViewBase>; | |
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Checks whether style scope and CSS state selectors are in sync. | ||
| 25 | + */ | ||
| 26 | + public isSelectorsLatestVersionApplied(): boolean | ||
| 22 | 27 | } | |
| 23 | 28 | ||
| 24 | 29 | export class StyleScope { | |
@@ -29,6 +34,9 @@ export class StyleScope { | |||
| 29 | 34 | public static createSelectorsFromImports(tree: SyntaxTree, keyframes: Object): RuleSet[]; | |
| 30 | 35 | public ensureSelectors(): number; | |
| 31 | 36 | ||
| 37 | + public isApplicationCssSelectorsLatestVersionApplied(): boolean; | ||
| 38 | + public isLocalCssSelectorsLatestVersionApplied(): boolean; | ||
| 39 | + | ||
| 32 | 40 | public applySelectors(view: ViewBase): void | |
| 33 | 41 | public query(options: Node): SelectorCore[]; | |
| 34 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,7 +271,7 @@ export function removeTaggedAdditionalCSS(tag: String | Number): Boolean { | |||
| 271 | 271 | changed = true; | |
| 272 | 272 | } | |
| 273 | 273 | } | |
| 274 | - if (changed) { mergeCssSelectors(); } | ||
| 274 | + if (changed) { mergeCssSelectors(); } | ||
| 275 | 275 | return changed; | |
| 276 | 276 | } | |
| 277 | 277 | ||
@@ -307,7 +307,7 @@ function onLiveSync(args: applicationCommon.CssChangedEventData): void { | |||
| 307 | 307 | loadCss(applicationCommon.getCssFileName()); | |
| 308 | 308 | } | |
| 309 | 309 | ||
| 310 | - const loadCss = profile(`"style-scope".loadCss`, (cssFile: string) => { | ||
| 310 | + export const loadCss = profile(`"style-scope".loadCss`, (cssFile: string) => { | ||
| 311 | 311 | if (!cssFile) { | |
| 312 | 312 | return undefined; | |
| 313 | 313 | } | |
@@ -343,6 +343,7 @@ export class CssState { | |||
| 343 | 343 | _appliedChangeMap: Readonly<ChangeMap<ViewBase>>; | |
| 344 | 344 | _appliedPropertyValues: Readonly<{}>; | |
| 345 | 345 | _appliedAnimations: ReadonlyArray<kam.KeyframeAnimation>; | |
| 346 | + _appliedSelectorsVersion: number; | ||
| 346 | 347 | ||
| 347 | 348 | _match: SelectorsMatch<ViewBase>; | |
| 348 | 349 | _matchInvalid: boolean; | |
@@ -367,6 +368,15 @@ export class CssState { | |||
| 367 | 368 | } | |
| 368 | 369 | } | |
| 369 | 370 | ||
| 371 | + public isSelectorsLatestVersionApplied(): boolean { | ||
| 372 | + if (this._appliedSelectorsVersion && this.view._styleScope) { | ||
| 373 | + this.view._styleScope.ensureSelectors(); | ||
| 374 | + return this.view._styleScope._getSelectorsVersion() === this._appliedSelectorsVersion; | ||
| 375 | + } else { | ||
| 376 | + return true; | ||
| 377 | + } | ||
| 378 | + } | ||
| 379 | + | ||
| 370 | 380 | public onLoaded(): void { | |
| 371 | 381 | if (this._matchInvalid) { | |
| 372 | 382 | this.updateMatch(); | |
@@ -381,6 +391,7 @@ export class CssState { | |||
| 381 | 391 | ||
| 382 | 392 | @profile | |
| 383 | 393 | private updateMatch() { | |
| 394 | + this._appliedSelectorsVersion = this.view._styleScope._getSelectorsVersion(); | ||
| 384 | 395 | this._match = this.view._styleScope ? this.view._styleScope.matchSelectors(this.view) : CssState.emptyMatch; | |
| 385 | 396 | this._matchInvalid = false; | |
| 386 | 397 | } | |
@@ -597,8 +608,8 @@ export class StyleScope { | |||
| 597 | 608 | } | |
| 598 | 609 | ||
| 599 | 610 | public ensureSelectors(): number { | |
| 600 | - if (this._applicationCssSelectorsAppliedVersion !== applicationCssSelectorVersion || | ||
| 601 | - this._localCssSelectorVersion !== this._localCssSelectorsAppliedVersion || | ||
| 611 | + if (!this.isApplicationCssSelectorsLatestVersionApplied() || | ||
| 612 | + !this.isLocalCssSelectorsLatestVersionApplied() || | ||
| 602 | 613 | !this._mergedCssSelectors) { | |
| 603 | 614 | ||
| 604 | 615 | this._createSelectors(); | |
@@ -607,6 +618,14 @@ export class StyleScope { | |||
| 607 | 618 | return this._getSelectorsVersion(); | |
| 608 | 619 | } | |
| 609 | 620 | ||
| 621 | + public isApplicationCssSelectorsLatestVersionApplied(): boolean { | ||
| 622 | + return this._applicationCssSelectorsAppliedVersion === applicationCssSelectorVersion; | ||
| 623 | + } | ||
| 624 | + | ||
| 625 | + public isLocalCssSelectorsLatestVersionApplied(): boolean { | ||
| 626 | + return this._localCssSelectorsAppliedVersion === this._localCssSelectorVersion; | ||
| 627 | + } | ||
| 628 | + | ||
| 610 | 629 | @profile | |
| 611 | 630 | private _createSelectors() { | |
| 612 | 631 | let toMerge: RuleSet[][] = []; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,4 +26,4 @@ | |||
| 26 | 26 | "tns-core-modules/*": ["tns-core-modules/*"] | |
| 27 | 27 | } | |
| 28 | 28 | } | |
| 29 | - } | ||
| 29 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments