| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4d6733d commit 7c22ffe
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Button { | ||
| 2 | + color: cyan; | ||
| 3 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ import * as app from "tns-core-modules/application/application"; | |||
| 5 | 5 | import * as frame from "tns-core-modules/ui/frame"; | |
| 6 | 6 | ||
| 7 | 7 | import { Color } from "tns-core-modules/color"; | |
| 8 | - import { isAndroid } from "tns-core-modules/platform"; | ||
| 9 | 8 | import { createViewFromEntry } from "tns-core-modules/ui/builder"; | |
| 10 | 9 | import { Page } from "tns-core-modules/ui/page"; | |
| 11 | 10 | import { Frame } from "tns-core-modules/ui/frame"; | |
@@ -20,6 +19,7 @@ const buttonHtmlPageFileName = "./livesync/livesync-button-page.html"; | |||
| 20 | 19 | const buttonXmlPageFileName = "./livesync/livesync-button-page.xml"; | |
| 21 | 20 | const buttonJsPageFileName = "./livesync/livesync-button-page.js"; | |
| 22 | 21 | const buttonTsPageFileName = "./livesync/livesync-button-page.ts"; | |
| 22 | + const buttonScssPageFileName = "./livesync/livesync-button-page.scss"; | ||
| 23 | 23 | const labelPageModuleName = "livesync/livesync-label-page"; | |
| 24 | 24 | ||
| 25 | 25 | const green = new Color("green"); | |
@@ -60,6 +60,36 @@ export function test_onLiveSync_ModuleContext_Markup_XmlFile() { | |||
| 60 | 60 | _test_onLiveSync_ModuleReplace({ type: "markup", path: buttonXmlPageFileName }); | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | + export function test_onLiveSync_ModuleContext_Markup_Script_XmlFile() { | ||
| 64 | + _test_onLiveSync_ModuleReplace_Multiple([ | ||
| 65 | + { type: "script", path: buttonTsPageFileName }, | ||
| 66 | + { type: "markup", path: buttonXmlPageFileName } | ||
| 67 | + ]); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + export function test_onLiveSync_ModuleContext_Markup_Script_Style_XmlFile() { | ||
| 71 | + _test_onLiveSync_ModuleReplace_Multiple([ | ||
| 72 | + { type: "script", path: buttonTsPageFileName }, | ||
| 73 | + { type: "markup", path: buttonXmlPageFileName }, | ||
| 74 | + { type: "style", path: buttonScssPageFileName } | ||
| 75 | + ]); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + export function test_onLiveSync_ModuleContext_Markup_Script_HtmlFile() { | ||
| 79 | + _test_onLiveSync_ModuleReplace_Multiple([ | ||
| 80 | + { type: "script", path: buttonTsPageFileName }, | ||
| 81 | + { type: "markup", path: buttonHtmlPageFileName } | ||
| 82 | + ]); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + export function test_onLiveSync_ModuleContext_Markup_Script_Style_HtmlFile() { | ||
| 86 | + _test_onLiveSync_ModuleReplace_Multiple([ | ||
| 87 | + { type: "script", path: buttonTsPageFileName }, | ||
| 88 | + { type: "markup", path: buttonHtmlPageFileName }, | ||
| 89 | + { type: "style", path: buttonScssPageFileName } | ||
| 90 | + ]); | ||
| 91 | + } | ||
| 92 | + | ||
| 63 | 93 | export function setUp() { | |
| 64 | 94 | const labelPage = <Page>createViewFromEntry(({ moduleName: labelPageModuleName })); | |
| 65 | 95 | helper.navigate(() => labelPage); | |
@@ -121,6 +151,28 @@ function _test_onLiveSync_ModuleReplace(context: { type, path }) { | |||
| 121 | 151 | TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, "Pages are different!"); | |
| 122 | 152 | } | |
| 123 | 153 | ||
| 154 | + function _test_onLiveSync_ModuleReplace_Multiple(context: { type: string, path: string }[]) { | ||
| 155 | + const pageBeforeNavigation = helper.getCurrentPage(); | ||
| 156 | + const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName })); | ||
| 157 | + helper.navigateWithHistory(() => buttonPage); | ||
| 158 | + | ||
| 159 | + context.forEach(item => { | ||
| 160 | + global.__onLiveSync(item); | ||
| 161 | + }); | ||
| 162 | + | ||
| 163 | + const topmostFrame = frame.topmost(); | ||
| 164 | + waitUntilLivesyncComplete(topmostFrame); | ||
| 165 | + TKUnit.assertTrue(topmostFrame.currentPage.getViewById("button").isLoaded, "Button page is NOT loaded!"); | ||
| 166 | + TKUnit.assertEqual(topmostFrame.backStack.length, 1, "Backstack is clean!"); | ||
| 167 | + TKUnit.assertTrue(topmostFrame.canGoBack(), "Can NOT go back!"); | ||
| 168 | + | ||
| 169 | + helper.goBack(); | ||
| 170 | + const pageAfterBackNavigation = helper.getCurrentPage(); | ||
| 171 | + TKUnit.assertTrue(topmostFrame.currentPage.getViewById("label").isLoaded, "Label page is NOT loaded!"); | ||
| 172 | + TKUnit.assertEqual(topmostFrame.backStack.length, 0, "Backstack is NOT clean!"); | ||
| 173 | + TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, "Pages are different!"); | ||
| 174 | + } | ||
| 175 | + | ||
| 124 | 176 | function _test_onLiveSync_ModuleContext_TypeStyle(context: { type, path }) { | |
| 125 | 177 | const pageBeforeNavigation = helper.getCurrentPage(); | |
| 126 | 178 | const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName })); | |
@@ -146,5 +198,5 @@ function _test_onLiveSync_ModuleContext_TypeStyle(context: { type, path }) { | |||
| 146 | 198 | } | |
| 147 | 199 | ||
| 148 | 200 | function waitUntilLivesyncComplete(frame: Frame) { | |
| 149 | - TKUnit.waitUntilReady(() => frame._executingEntry === null); | ||
| 201 | + TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty()); | ||
| 150 | 202 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -735,8 +735,7 @@ function transitionOrAnimationCompleted(entry: ExpandedEntry): void { | |||
| 735 | 735 | // Will be null if Frame is shown modally... | |
| 736 | 736 | // transitionOrAnimationCompleted fires again (probably bug in android). | |
| 737 | 737 | if (current) { | |
| 738 | - const navType = frame.navigationType; | ||
| 739 | - setTimeout(() => frame.setCurrent(current, navType)); | ||
| 738 | + setTimeout(() => frame.setCurrent(current)); | ||
| 740 | 739 | } | |
| 741 | 740 | } else { | |
| 742 | 741 | completedEntries.set(frameId, entry); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ import { getModuleName } from "../../utils/utils"; | |||
| 13 | 13 | export * from "../core/view"; | |
| 14 | 14 | ||
| 15 | 15 | export enum NavigationType { | |
| 16 | + unset, | ||
| 16 | 17 | back, | |
| 17 | 18 | forward, | |
| 18 | 19 | replace | |
@@ -37,7 +38,9 @@ function buildEntryFromArgs(arg: any): NavigationEntry { | |||
| 37 | 38 | ||
| 38 | 39 | export interface NavigationContext { | |
| 39 | 40 | entry: BackstackEntry; | |
| 41 | + // TODO: remove isBackNavigation for NativeScript 6.0 | ||
| 40 | 42 | isBackNavigation: boolean; | |
| 43 | + navigationType: NavigationType | ||
| 41 | 44 | } | |
| 42 | 45 | ||
| 43 | 46 | @CSSType("Frame") | |
@@ -51,11 +54,10 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 51 | 54 | ||
| 52 | 55 | public actionBarVisibility: "auto" | "never" | "always"; | |
| 53 | 56 | public _currentEntry: BackstackEntry; | |
| 54 | - public _executingEntry: BackstackEntry; | ||
| 57 | + public _executingContext: NavigationContext; | ||
| 55 | 58 | public _isInFrameStack = false; | |
| 56 | 59 | public static defaultAnimatedNavigation = true; | |
| 57 | 60 | public static defaultTransition: NavigationTransition; | |
| 58 | - public navigationType: NavigationType; | ||
| 59 | 61 | ||
| 60 | 62 | // TODO: Currently our navigation will not be synchronized in case users directly call native navigation methods like Activity.startActivity. | |
| 61 | 63 | ||
@@ -75,7 +77,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 75 | 77 | let previousForwardNotInBackstack = false; | |
| 76 | 78 | this._navigationQueue.forEach(item => { | |
| 77 | 79 | const entry = item.entry; | |
| 78 | - if (item.isBackNavigation) { | ||
| 80 | + const isBackNavigation = item.navigationType === NavigationType.back; | ||
| 81 | + if (isBackNavigation) { | ||
| 79 | 82 | previousForwardNotInBackstack = false; | |
| 80 | 83 | if (!entry) { | |
| 81 | 84 | backstack--; | |
@@ -135,7 +138,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 135 | 138 | ||
| 136 | 139 | const navigationContext: NavigationContext = { | |
| 137 | 140 | entry: backstackEntry, | |
| 138 | - isBackNavigation: true | ||
| 141 | + isBackNavigation: true, | ||
| 142 | + navigationType: NavigationType.back | ||
| 139 | 143 | } | |
| 140 | 144 | ||
| 141 | 145 | this._navigationQueue.push(navigationContext); | |
@@ -203,7 +207,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 203 | 207 | ||
| 204 | 208 | const navigationContext: NavigationContext = { | |
| 205 | 209 | entry: backstackEntry, | |
| 206 | - isBackNavigation: false | ||
| 210 | + isBackNavigation: false, | ||
| 211 | + navigationType: NavigationType.forward | ||
| 207 | 212 | } | |
| 208 | 213 | ||
| 209 | 214 | this._navigationQueue.push(navigationContext); | |
@@ -214,7 +219,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 214 | 219 | return this._currentEntry === entry; | |
| 215 | 220 | } | |
| 216 | 221 | ||
| 217 | - public setCurrent(entry: BackstackEntry, navigationType: NavigationType): void { | ||
| 222 | + public setCurrent(entry: BackstackEntry): void { | ||
| 218 | 223 | const newPage = entry.resolvedPage; | |
| 219 | 224 | // In case we navigated forward to a page that was in the backstack | |
| 220 | 225 | // with clearHistory: true | |
@@ -225,17 +230,19 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 225 | 230 | ||
| 226 | 231 | this._currentEntry = entry; | |
| 227 | 232 | ||
| 233 | + const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; | ||
| 234 | + const navigationType = navigationContext.navigationType; | ||
| 228 | 235 | const isBack = navigationType === NavigationType.back; | |
| 229 | 236 | if (isBack) { | |
| 230 | 237 | this._pushInFrameStack(); | |
| 231 | 238 | } | |
| 232 | 239 | ||
| 233 | 240 | newPage.onNavigatedTo(isBack); | |
| 234 | 241 | ||
| 235 | - // Reset executing entry after NavigatedTo is raised; | ||
| 242 | + // Reset executing context after NavigatedTo is raised; | ||
| 236 | 243 | // we do not want to execute two navigations in parallel in case | |
| 237 | 244 | // additional navigation is triggered from the NavigatedTo handler. | |
| 238 | - this._executingEntry = null; | ||
| 245 | + this._executingContext = null; | ||
| 239 | 246 | } | |
| 240 | 247 | ||
| 241 | 248 | public _updateBackstack(entry: BackstackEntry, navigationType: NavigationType): void { | |
@@ -342,13 +349,14 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 342 | 349 | } | |
| 343 | 350 | ||
| 344 | 351 | protected _processNextNavigationEntry() { | |
| 345 | - if (!this.isLoaded || this._executingEntry) { | ||
| 352 | + if (!this.isLoaded || this._executingContext) { | ||
| 346 | 353 | return; | |
| 347 | 354 | } | |
| 348 | 355 | ||
| 349 | 356 | if (this._navigationQueue.length > 0) { | |
| 350 | 357 | const navigationContext = this._navigationQueue[0]; | |
| 351 | - if (navigationContext.isBackNavigation) { | ||
| 358 | + const isBackNavigation = navigationContext.navigationType === NavigationType.back; | ||
| 359 | + if (isBackNavigation) { | ||
| 352 | 360 | this.performGoBack(navigationContext); | |
| 353 | 361 | } else { | |
| 354 | 362 | this.performNavigation(navigationContext); | |
@@ -358,10 +366,12 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 358 | 366 | ||
| 359 | 367 | @profile | |
| 360 | 368 | public performNavigation(navigationContext: NavigationContext) { | |
| 361 | - const navContext = navigationContext.entry; | ||
| 362 | - this._executingEntry = navContext; | ||
| 363 | - this._onNavigatingTo(navContext, navigationContext.isBackNavigation); | ||
| 364 | - this._navigateCore(navContext); | ||
| 369 | + this._executingContext = navigationContext; | ||
| 370 | + | ||
| 371 | + const backstackEntry = navigationContext.entry; | ||
| 372 | + const isBackNavigation = navigationContext.navigationType === NavigationType.back; | ||
| 373 | + this._onNavigatingTo(backstackEntry, isBackNavigation); | ||
| 374 | + this._navigateCore(backstackEntry); | ||
| 365 | 375 | } | |
| 366 | 376 | ||
| 367 | 377 | @profile | |
@@ -373,7 +383,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 373 | 383 | navigationContext.entry = backstackEntry; | |
| 374 | 384 | } | |
| 375 | 385 | ||
| 376 | - this._executingEntry = backstackEntry; | ||
| 386 | + this._executingContext = navigationContext; | ||
| 377 | 387 | this._onNavigatingTo(backstackEntry, true); | |
| 378 | 388 | this._goBackCore(backstackEntry); | |
| 379 | 389 | } | |
@@ -643,9 +653,6 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 643 | 653 | } | |
| 644 | 654 | ||
| 645 | 655 | protected replacePage(context: ModuleContext): void { | |
| 646 | - // Set NavigationType.replace for HMR. | ||
| 647 | - // In IOS on `viewDidAppear()` this will be set to NavigationType.forward. | ||
| 648 | - this.navigationType = NavigationType.replace; | ||
| 649 | 656 | const currentBackstackEntry = this._currentEntry; | |
| 650 | 657 | const contextModuleName = getModuleName(context.path); | |
| 651 | 658 | ||
@@ -658,10 +665,15 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 658 | 665 | frameId: currentBackstackEntry.frameId | |
| 659 | 666 | }; | |
| 660 | 667 | ||
| 661 | - const navContext: NavigationContext = { entry: newBackstackEntry, isBackNavigation: false }; | ||
| 662 | - this.performNavigation(navContext); | ||
| 663 | - } | ||
| 668 | + const navigationContext: NavigationContext = { | ||
| 669 | + entry: newBackstackEntry, | ||
| 670 | + isBackNavigation: false, | ||
| 671 | + navigationType: NavigationType.replace | ||
| 672 | + }; | ||
| 664 | 673 | ||
| 674 | + this._navigationQueue.push(navigationContext); | ||
| 675 | + this._processNextNavigationEntry(); | ||
| 676 | + } | ||
| 665 | 677 | } | |
| 666 | 678 | ||
| 667 | 679 | export function getFrameById(id: string): FrameBase { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments