mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(frame): rework frame retrieval api (#5527)
Rework the frame api to support working with multiple Frames. * frameModule.topmost() - now returns the last navigated Frame or the currently selected tab item's Frame if the tab item's view is a Frame. * frameModule.getFrameById(id: string) - returns a navigated Frame by id. * args.object.page.frame - can be used in page elements event handlers. Returns the Frame of the current element's page. * chore: Update madge-android npm script path
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// >> frame-require
|
||||
import { topmost, NavigationEntry } from "tns-core-modules/ui/frame";
|
||||
import { Frame, getFrameById, topmost, NavigationEntry } from "tns-core-modules/ui/frame";
|
||||
// << frame-require
|
||||
|
||||
import { getRootView } from "tns-core-modules/application";
|
||||
import { Label } from "tns-core-modules/ui/label";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
import * as helper from "../helper";
|
||||
@@ -223,4 +224,40 @@ export function test_page_parent_when_navigate_back() {
|
||||
});
|
||||
|
||||
pages.length = 0;
|
||||
}
|
||||
|
||||
export function test_frame_retrieval_API_when_navigating() {
|
||||
const rootView = getRootView();
|
||||
|
||||
const initialFrame = new Frame();
|
||||
initialFrame.id = "initialFrame";
|
||||
initialFrame.navigate(() => new Page());
|
||||
|
||||
const initialTopmost = topmost();
|
||||
const initialFrameById = getFrameById("initialFrame");
|
||||
|
||||
TKUnit.assertEqual(initialTopmost, initialFrame);
|
||||
TKUnit.assertEqual(initialFrameById, initialFrame);
|
||||
|
||||
const newFrame = new Frame();
|
||||
newFrame.id = "newFrame";
|
||||
newFrame.navigate(() => new Page());
|
||||
|
||||
const newTopmost = topmost();
|
||||
const newFrameById = getFrameById("newFrame");
|
||||
|
||||
TKUnit.assertEqual(newTopmost, newFrame);
|
||||
TKUnit.assertEqual(newFrameById, newFrame);
|
||||
|
||||
initialFrame.navigate(() => new Page());
|
||||
|
||||
const previousTopmost = topmost();
|
||||
const previousFrameById = getFrameById("initialFrame");
|
||||
|
||||
TKUnit.assertEqual(previousTopmost, initialFrame);
|
||||
TKUnit.assertEqual(previousFrameById, initialFrame);
|
||||
|
||||
// clean up the frame stack
|
||||
initialFrame._removeFromFrameStack();
|
||||
newFrame._removeFromFrameStack();
|
||||
}
|
||||
Reference in New Issue
Block a user