| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,11 @@ | |||
| 1 | 1 | import * as TKUnit from "../TKUnit"; | |
| 2 | 2 | import { EventData, Page, NavigatedData } from "tns-core-modules/ui/page"; | |
| 3 | 3 | import { topmost as topmostFrame, NavigationTransition } from "tns-core-modules/ui/frame"; | |
| 4 | + import { StackLayout, } from "tns-core-modules/ui/layouts/stack-layout"; | ||
| 5 | + import { GridLayout, } from "tns-core-modules/ui/layouts/grid-layout"; | ||
| 4 | 6 | import { Color } from "tns-core-modules/color"; | |
| 5 | 7 | import * as helper from "../ui/helper"; | |
| 6 | - | ||
| 8 | + import * as frame from "tns-core-modules/ui/frame"; | ||
| 7 | 9 | // Creates a random colorful page full of meaningless stuff. | |
| 8 | 10 | let id = 0; | |
| 9 | 11 | let pageFactory = function (): Page { | |
@@ -51,6 +53,65 @@ export function test_backstackVisible_WithTransition() { | |||
| 51 | 53 | _test_backstackVisible({ name: "fade", duration: 10 }); | |
| 52 | 54 | } | |
| 53 | 55 | ||
| 56 | + export function test_backAndForwardParentPage_nestedFrames() { | ||
| 57 | + const topmost = topmostFrame(); | ||
| 58 | + const mainTestPage = topmost.currentPage; | ||
| 59 | + let innerFrame; | ||
| 60 | + | ||
| 61 | + const page = (title) => { | ||
| 62 | + const p = new Page(); | ||
| 63 | + p["tag"] = title; | ||
| 64 | + return p; | ||
| 65 | + }; | ||
| 66 | + | ||
| 67 | + const parentPage = (title, innerPage) => { | ||
| 68 | + const parentPage = new Page(); | ||
| 69 | + parentPage["tag"] = title; | ||
| 70 | + | ||
| 71 | + const stack = new StackLayout(); | ||
| 72 | + innerFrame = new frame.Frame(); | ||
| 73 | + innerFrame.navigate({ create: () => innerPage }); | ||
| 74 | + stack.addChild(innerFrame); | ||
| 75 | + parentPage.content = stack; | ||
| 76 | + | ||
| 77 | + return parentPage; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + const back = pages => topmostFrame().goBack(topmostFrame().backStack[topmostFrame().backStack.length - pages]); | ||
| 81 | + const currentPageMustBe = tag => TKUnit.assertEqual(topmostFrame().currentPage["tag"], tag, "Expected current page to be " + tag + " it was " + topmostFrame().currentPage["tag"] + " instead."); | ||
| 82 | + | ||
| 83 | + let parentPage1, parentPage2, innerPage1, innerPage2; | ||
| 84 | + innerPage1 = page("InnerPage1"); | ||
| 85 | + innerPage2 = page("InnerPage2"); | ||
| 86 | + parentPage1 = page("ParentPage1"); | ||
| 87 | + parentPage2 = parentPage("ParentPage2", innerPage1); | ||
| 88 | + | ||
| 89 | + helper.waitUntilNavigatedTo(parentPage1, () => topmost.navigate({ create: () => parentPage1 })); | ||
| 90 | + currentPageMustBe("ParentPage1"); | ||
| 91 | + | ||
| 92 | + helper.waitUntilNavigatedTo(parentPage2, () => topmost.navigate({ create: () => parentPage2 })); | ||
| 93 | + currentPageMustBe("ParentPage2"); | ||
| 94 | + | ||
| 95 | + helper.waitUntilNavigatedTo(innerPage2, () => innerFrame.navigate({ create: () => innerPage2 })); | ||
| 96 | + currentPageMustBe("InnerPage2"); | ||
| 97 | + | ||
| 98 | + helper.waitUntilNavigatedTo(innerPage1, () => frame.goBack()); | ||
| 99 | + currentPageMustBe("InnerPage1"); | ||
| 100 | + | ||
| 101 | + helper.waitUntilNavigatedTo(parentPage1, () => frame.goBack()); | ||
| 102 | + currentPageMustBe("ParentPage1"); | ||
| 103 | + | ||
| 104 | + helper.waitUntilNavigatedTo(parentPage2, () => topmost.navigate({ create: () => parentPage2 })); | ||
| 105 | + currentPageMustBe("ParentPage2"); | ||
| 106 | + | ||
| 107 | + back(2); | ||
| 108 | + TKUnit.waitUntilReady(() => topmostFrame().navigationQueueIsEmpty()); | ||
| 109 | + | ||
| 110 | + const frameStack = frame.stack(); | ||
| 111 | + TKUnit.assertEqual(frameStack.length, 1, "There should be only one frame left in the stack"); | ||
| 112 | + TKUnit.assertEqual(topmostFrame().currentPage, mainTestPage, "We should be on the main test page at the end of the test."); | ||
| 113 | + } | ||
| 114 | + | ||
| 54 | 115 | function _test_backToEntry(transition?: NavigationTransition) { | |
| 55 | 116 | const topmost = topmostFrame(); | |
| 56 | 117 | const page = (tag) => () => { | |
@@ -362,10 +423,10 @@ function _test_NavigationEvents_WithClearHistory(transition?: NavigationTransiti | |||
| 362 | 423 | // Go to second page | |
| 363 | 424 | helper.navigateWithEntry({ create: secondPageFactory, transition: transition, animated: !!transition, clearHistory: true }); | |
| 364 | 425 | ||
| 365 | - const expectedMainPageEvents = [ "main-page navigatingFrom forward", "main-page navigatedFrom forward" ]; | ||
| 426 | + const expectedMainPageEvents = ["main-page navigatingFrom forward", "main-page navigatedFrom forward"]; | ||
| 366 | 427 | TKUnit.arrayAssert(actualMainPageEvents, expectedMainPageEvents, "Actual main-page events are different from expected."); | |
| 367 | 428 | ||
| 368 | - const expectedSecondPageEvents = [ "second-page navigatingTo forward", "second-page navigatedTo forward" ]; | ||
| 429 | + const expectedSecondPageEvents = ["second-page navigatingTo forward", "second-page navigatedTo forward"]; | ||
| 369 | 430 | TKUnit.arrayAssert(actualSecondPageEvents, expectedSecondPageEvents, "Actual main-page events are different from expected."); | |
| 370 | 431 | ||
| 371 | 432 | TKUnit.assertEqual(topmost.currentPage, secondPage, "We should be on the second page at the end of the test."); | |
@@ -393,7 +454,7 @@ function _test_Navigate_From_Page_Event_Handler(eventName: string) { | |||
| 393 | 454 | const firstPageFactory = function (): Page { | |
| 394 | 455 | const firstPage = new Page(); | |
| 395 | 456 | firstPage.id = "first-page"; | |
| 396 | - firstPage.on(eventName, (args: EventData) => { | ||
| 457 | + firstPage.on(eventName, (args: EventData) => { | ||
| 397 | 458 | const page = <Page>args.object; | |
| 398 | 459 | const frame = page.frame; | |
| 399 | 460 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ import { Frame as FrameDefinition, NavigationEntry, BackstackEntry, NavigationTr | |||
| 3 | 3 | import { Page } from "../page"; | |
| 4 | 4 | ||
| 5 | 5 | // Types. | |
| 6 | + import { getAncestor } from "../core/view/view-common"; | ||
| 6 | 7 | import { View, CustomLayoutView, isIOS, isAndroid, traceEnabled, traceWrite, traceCategories, Property, CSSType } from "../core/view"; | |
| 7 | 8 | import { createViewFromEntry } from "../builder"; | |
| 8 | 9 | import { profile } from "../../profiling"; | |
@@ -215,6 +216,10 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 215 | 216 | ||
| 216 | 217 | this._currentEntry = entry; | |
| 217 | 218 | ||
| 219 | + if (isBack) { | ||
| 220 | + this._pushInFrameStack(); | ||
| 221 | + } | ||
| 222 | + | ||
| 218 | 223 | newPage.onNavigatedTo(isBack); | |
| 219 | 224 | ||
| 220 | 225 | // Reset executing entry after NavigatedTo is raised; | |
@@ -573,6 +578,22 @@ export function goBack(): boolean { | |||
| 573 | 578 | if (top && top.canGoBack()) { | |
| 574 | 579 | top.goBack(); | |
| 575 | 580 | return true; | |
| 581 | + } else if (top) { | ||
| 582 | + let parentFrameCanGoBack = false; | ||
| 583 | + let parentFrame = <FrameBase>getAncestor(top, "Frame"); | ||
| 584 | + | ||
| 585 | + while (parentFrame && !parentFrameCanGoBack) { | ||
| 586 | + if (parentFrame && parentFrame.canGoBack()) { | ||
| 587 | + parentFrameCanGoBack = true; | ||
| 588 | + } else { | ||
| 589 | + parentFrame = <FrameBase>getAncestor(top, "Frame"); | ||
| 590 | + } | ||
| 591 | + } | ||
| 592 | + | ||
| 593 | + if (parentFrame && parentFrameCanGoBack) { | ||
| 594 | + parentFrame.goBack(); | ||
| 595 | + return true; | ||
| 596 | + } | ||
| 576 | 597 | } | |
| 577 | 598 | ||
| 578 | 599 | if (frameStack.length > 1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,8 +204,8 @@ export class Frame extends FrameBase { | |||
| 204 | 204 | // however, we must add a fragment.isAdded() guard as our logic will try to | |
| 205 | 205 | // explicitly remove the already removed child fragment causing an | |
| 206 | 206 | // IllegalStateException: Fragment has not been attached yet. | |
| 207 | - if (!this._currentEntry || | ||
| 208 | - !this._currentEntry.fragment || | ||
| 207 | + if (!this._currentEntry || | ||
| 208 | + !this._currentEntry.fragment || | ||
| 209 | 209 | !this._currentEntry.fragment.isAdded()) { | |
| 210 | 210 | return; | |
| 211 | 211 | } | |
@@ -423,6 +423,7 @@ export class Frame extends FrameBase { | |||
| 423 | 423 | } | |
| 424 | 424 | ||
| 425 | 425 | this._android.rootViewGroup = null; | |
| 426 | + this._removeFromFrameStack(); | ||
| 426 | 427 | super.disposeNativeView(); | |
| 427 | 428 | } | |
| 428 | 429 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,11 @@ export class Frame extends FrameBase { | |||
| 36 | 36 | return this.viewController.view; | |
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | + public disposeNativeView() { | ||
| 40 | + this._removeFromFrameStack(); | ||
| 41 | + super.disposeNativeView(); | ||
| 42 | + } | ||
| 43 | + | ||
| 39 | 44 | public get ios(): iOSFrame { | |
| 40 | 45 | return this._ios; | |
| 41 | 46 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments