| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 45bf5b8 commit dfa70dd
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,7 +84,7 @@ | |||
| 84 | 84 | "tslint": "tslint --config build/tslint.json 'tns-core-modules/**/*.ts' 'tests/**/*.ts' 'apps/**/*.ts' 'e2e/**/*.ts' -e '**/node_modules/**' -e '**/platforms/**'", | |
| 85 | 85 | "madge-ios": "tsc --skipLibCheck && tns prepare ios --path tests && madge --circular tests/platforms/ios/tests/app/tns_modules/tns-core-modules", | |
| 86 | 86 | "madge-ios-image": "tsc --skipLibCheck && tns prepare ios --path tests && madge --image graph-tests-ios.svg tests/platforms/ios/tests/app/tns_modules/tns-core-modules", | |
| 87 | - "madge-android": "tsc --skipLibCheck && tns prepare android --path tests && madge --circular tests/platforms/android/src/main/assets/app/tns_modules/tns-core-modules", | ||
| 88 | - "madge-android-image": "tsc --skipLibCheck && tns prepare android --path tests && madge --image graph-tests-android.svg tests/platforms/android/src/main/assets/app/tns_modules/tns-core-modules" | ||
| 87 | + "madge-android": "tsc --skipLibCheck && tns prepare android --path tests && madge --circular tests/platforms/android/app/src/main/assets/app/tns_modules/tns-core-modules", | ||
| 88 | + "madge-android-image": "tsc --skipLibCheck && tns prepare android --path tests && madge --image graph-tests-android.svg tests/platforms/android/app/src/main/assets/app/tns_modules/tns-core-modules" | ||
| 89 | 89 | } | |
| 90 | 90 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | // >> frame-require | |
| 2 | - import { topmost, NavigationEntry } from "tns-core-modules/ui/frame"; | ||
| 2 | + import { Frame, getFrameById, topmost, NavigationEntry } from "tns-core-modules/ui/frame"; | ||
| 3 | 3 | // << frame-require | |
| 4 | 4 | ||
| 5 | + import { getRootView } from "tns-core-modules/application"; | ||
| 5 | 6 | import { Label } from "tns-core-modules/ui/label"; | |
| 6 | 7 | import { Page } from "tns-core-modules/ui/page"; | |
| 7 | 8 | import * as helper from "../helper"; | |
@@ -223,4 +224,40 @@ export function test_page_parent_when_navigate_back() { | |||
| 223 | 224 | }); | |
| 224 | 225 | ||
| 225 | 226 | pages.length = 0; | |
| 227 | + } | ||
| 228 | + | ||
| 229 | + export function test_frame_retrieval_API_when_navigating() { | ||
| 230 | + const rootView = getRootView(); | ||
| 231 | + | ||
| 232 | + const initialFrame = new Frame(); | ||
| 233 | + initialFrame.id = "initialFrame"; | ||
| 234 | + initialFrame.navigate(() => new Page()); | ||
| 235 | + | ||
| 236 | + const initialTopmost = topmost(); | ||
| 237 | + const initialFrameById = getFrameById("initialFrame"); | ||
| 238 | + | ||
| 239 | + TKUnit.assertEqual(initialTopmost, initialFrame); | ||
| 240 | + TKUnit.assertEqual(initialFrameById, initialFrame); | ||
| 241 | + | ||
| 242 | + const newFrame = new Frame(); | ||
| 243 | + newFrame.id = "newFrame"; | ||
| 244 | + newFrame.navigate(() => new Page()); | ||
| 245 | + | ||
| 246 | + const newTopmost = topmost(); | ||
| 247 | + const newFrameById = getFrameById("newFrame"); | ||
| 248 | + | ||
| 249 | + TKUnit.assertEqual(newTopmost, newFrame); | ||
| 250 | + TKUnit.assertEqual(newFrameById, newFrame); | ||
| 251 | + | ||
| 252 | + initialFrame.navigate(() => new Page()); | ||
| 253 | + | ||
| 254 | + const previousTopmost = topmost(); | ||
| 255 | + const previousFrameById = getFrameById("initialFrame"); | ||
| 256 | + | ||
| 257 | + TKUnit.assertEqual(previousTopmost, initialFrame); | ||
| 258 | + TKUnit.assertEqual(previousFrameById, initialFrame); | ||
| 259 | + | ||
| 260 | + // clean up the frame stack | ||
| 261 | + initialFrame._removeFromFrameStack(); | ||
| 262 | + newFrame._removeFromFrameStack(); | ||
| 226 | 263 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -403,10 +403,15 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 403 | 403 | } | |
| 404 | 404 | ||
| 405 | 405 | public _pushInFrameStack() { | |
| 406 | - if (this._isInFrameStack) { | ||
| 406 | + if (this._isInFrameStack && frameStack[frameStack.length - 1] === this) { | ||
| 407 | 407 | return; | |
| 408 | 408 | } | |
| 409 | 409 | ||
| 410 | + if (this._isInFrameStack) { | ||
| 411 | + const indexOfFrame = frameStack.indexOf(this); | ||
| 412 | + frameStack.splice(indexOfFrame, 1); | ||
| 413 | + } | ||
| 414 | + | ||
| 410 | 415 | frameStack.push(this); | |
| 411 | 416 | this._isInFrameStack = true; | |
| 412 | 417 | } | |
@@ -425,7 +430,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 425 | 430 | this._isInFrameStack = false; | |
| 426 | 431 | } | |
| 427 | 432 | ||
| 428 | - private _removeFromFrameStack() { | ||
| 433 | + public _removeFromFrameStack() { | ||
| 429 | 434 | if (!this._isInFrameStack) { | |
| 430 | 435 | return; | |
| 431 | 436 | } | |
@@ -575,6 +580,10 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 575 | 580 | } | |
| 576 | 581 | } | |
| 577 | 582 | ||
| 583 | + export function getFrameById(id: string): FrameBase { | ||
| 584 | + return frameStack.find((frame) => frame.id && frame.id === id); | ||
| 585 | + } | ||
| 586 | + | ||
| 578 | 587 | export function topmost(): FrameBase { | |
| 579 | 588 | if (frameStack.length > 0) { | |
| 580 | 589 | return frameStack[frameStack.length - 1]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -597,7 +597,7 @@ function startActivity(activity: android.app.Activity, frameId: number) { | |||
| 597 | 597 | activity.startActivity(intent); | |
| 598 | 598 | } | |
| 599 | 599 | ||
| 600 | - function getFrameById(frameId: number): Frame { | ||
| 600 | + function getFrameByNumberId(frameId: number): Frame { | ||
| 601 | 601 | // Find the frame for this activity. | |
| 602 | 602 | for (let i = 0; i < framesCache.length; i++) { | |
| 603 | 603 | let aliveFrame = framesCache[i].get(); | |
@@ -676,7 +676,7 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { | |||
| 676 | 676 | if (!this.entry) { | |
| 677 | 677 | const args = fragment.getArguments(); | |
| 678 | 678 | const frameId = args.getInt(FRAMEID); | |
| 679 | - const frame = getFrameById(frameId); | ||
| 679 | + const frame = getFrameByNumberId(frameId); | ||
| 680 | 680 | if (!frame) { | |
| 681 | 681 | throw new Error(`Cannot find Frame for ${fragment}`); | |
| 682 | 682 | } | |
@@ -999,7 +999,7 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks { | |||
| 999 | 999 | if (!rootView) { | |
| 1000 | 1000 | // If we have frameId from extras - we are starting a new activity from navigation (e.g. new Frame().navigate())) | |
| 1001 | 1001 | // Then we check if we have frameId from savedInstanceState - this happens when Activity is destroyed but app was not (e.g. suspend) | |
| 1002 | - rootView = getFrameById(frameId) || new Frame(); | ||
| 1002 | + rootView = getFrameByNumberId(frameId) || new Frame(); | ||
| 1003 | 1003 | } | |
| 1004 | 1004 | ||
| 1005 | 1005 | if (rootView instanceof Frame) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,6 +145,14 @@ export class Frame extends View { | |||
| 145 | 145 | * @private | |
| 146 | 146 | */ | |
| 147 | 147 | _updateBackstack(entry: BackstackEntry, isBack: boolean): void; | |
| 148 | + /** | ||
| 149 | + * @private | ||
| 150 | + */ | ||
| 151 | + _pushInFrameStack(); | ||
| 152 | + /** | ||
| 153 | + * @private | ||
| 154 | + */ | ||
| 155 | + _removeFromFrameStack(); | ||
| 148 | 156 | /** | |
| 149 | 157 | * @private | |
| 150 | 158 | */ | |
@@ -170,6 +178,11 @@ export class Frame extends View { | |||
| 170 | 178 | */ | |
| 171 | 179 | export function setFragmentClass(clazz: any): void; | |
| 172 | 180 | ||
| 181 | + /** | ||
| 182 | + * Gets a frame by id. | ||
| 183 | + */ | ||
| 184 | + export function getFrameById(id: string): Frame; | ||
| 185 | + | ||
| 173 | 186 | /** | |
| 174 | 187 | * Gets the topmost frame in the frames stack. An application will typically has one frame instance. Multiple frames handle nested (hierarchical) navigation scenarios. | |
| 175 | 188 | */ | |
@@ -182,6 +195,7 @@ export function topmost(): Frame; | |||
| 182 | 195 | export function goBack(); | |
| 183 | 196 | ||
| 184 | 197 | /** | |
| 198 | + * Deprecated. Use getFrameById() if you want to retrieve a frame different than the topmost one. | ||
| 185 | 199 | * Gets the frames stack. | |
| 186 | 200 | */ | |
| 187 | 201 | export function stack(): Array<Frame>; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ import { | |||
| 11 | 11 | import { textTransformProperty, TextTransform, getTransformedText } from "../text-base"; | |
| 12 | 12 | import { fromFileOrResource } from "../../image-source"; | |
| 13 | 13 | import { RESOURCE_PREFIX, ad } from "../../utils/utils"; | |
| 14 | + import { Frame } from "../frame"; | ||
| 14 | 15 | ||
| 15 | 16 | export * from "./tab-view-common"; | |
| 16 | 17 | ||
@@ -473,6 +474,12 @@ export class TabView extends TabViewBase { | |||
| 473 | 474 | } | |
| 474 | 475 | }); | |
| 475 | 476 | ||
| 477 | + const newItem = items[newIndex]; | ||
| 478 | + const selectedView = newItem && newItem.view; | ||
| 479 | + if (selectedView instanceof Frame) { | ||
| 480 | + selectedView._pushInFrameStack(); | ||
| 481 | + } | ||
| 482 | + | ||
| 476 | 483 | toLoad.forEach(index => { | |
| 477 | 484 | const item = items[index]; | |
| 478 | 485 | if (this.isLoaded && items[index]) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ import { Page } from "../page"; | |||
| 13 | 13 | import { profile } from "../../profiling"; | |
| 14 | 14 | import * as uiUtils from "../utils"; | |
| 15 | 15 | import * as utils from "../../utils/utils"; | |
| 16 | + import { Frame } from "../frame"; | ||
| 16 | 17 | ||
| 17 | 18 | export * from "./tab-view-common"; | |
| 18 | 19 | ||
@@ -253,6 +254,11 @@ export class TabView extends TabViewBase { | |||
| 253 | 254 | ||
| 254 | 255 | const newItem = items[newIndex]; | |
| 255 | 256 | if (newItem && this.isLoaded) { | |
| 257 | + const selectedView = items[newIndex].view; | ||
| 258 | + if (selectedView instanceof Frame) { | ||
| 259 | + selectedView._pushInFrameStack(); | ||
| 260 | + } | ||
| 261 | + | ||
| 256 | 262 | newItem.loadView(newItem.view); | |
| 257 | 263 | } | |
| 258 | 264 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments