|
| 1 | +// TODO: Remove this and get it from global to decouple builder for angular |
| 2 | +import { Builder } from "../ui/builder/builder"; |
| 3 | +import { unsetValue, View } from "../ui/core/view/view"; |
| 4 | +import { Frame, NavigationEntry } from "../ui/frame/frame"; |
| 5 | +import { Page } from "../ui/page/page"; |
| 6 | + |
| 7 | +import * as TKUnit from "./tk-unit"; |
| 8 | + |
| 9 | +export let ASYNC = 0.2; |
| 10 | +export let MEMORY_ASYNC = 2; |
| 11 | + |
| 12 | +function navigate(pageFactory: () => Page, navigationContext?: any): Page { |
| 13 | + let entry: NavigationEntry = { create: pageFactory, animated: false, context: navigationContext, clearHistory: true }; |
| 14 | + |
| 15 | + return navigateWithEntry(entry); |
| 16 | +} |
| 17 | + |
| 18 | +function navigateWithHistory(pageFactory: () => Page, navigationContext?: any): Page { |
| 19 | + let entry: NavigationEntry = { create: pageFactory, animated: false, context: navigationContext, clearHistory: false }; |
| 20 | + |
| 21 | + return navigateWithEntry(entry); |
| 22 | +} |
| 23 | + |
| 24 | +export function asdf(moduleName: string, context?: any): Page { |
| 25 | + let entry: NavigationEntry = { moduleName: moduleName, context: context, animated: false, clearHistory: true }; |
| 26 | + |
| 27 | + return navigateWithEntry(entry); |
| 28 | +} |
| 29 | + |
| 30 | +function navigateToModule(moduleName: string, context?: any): Page { |
| 31 | + let entry: NavigationEntry = { moduleName: moduleName, context: context, animated: false, clearHistory: true }; |
| 32 | + |
| 33 | + return navigateWithEntry(entry); |
| 34 | +} |
| 35 | + |
| 36 | +function getCurrentPage(): Page { |
| 37 | + return Frame.topmost().currentPage; |
| 38 | +} |
| 39 | + |
| 40 | +function getClearCurrentPage(): Page { |
| 41 | + let page = Frame.topmost().currentPage; |
| 42 | + page.style.backgroundColor = unsetValue; |
| 43 | + page.style.color = unsetValue; |
| 44 | + page.bindingContext = unsetValue; |
| 45 | + page.className = unsetValue; |
| 46 | + page.id = unsetValue; |
| 47 | + page.css = ""; |
| 48 | + |
| 49 | + return page; |
| 50 | +} |
| 51 | + |
| 52 | +function waitUntilNavigatedTo(page: Page, action: Function) { |
| 53 | + let completed = false; |
| 54 | + function navigatedTo(args) { |
| 55 | + args.object.page.off("navigatedTo", navigatedTo); |
| 56 | + completed = true; |
| 57 | + } |
| 58 | + |
| 59 | + page.on("navigatedTo", navigatedTo); |
| 60 | + action(); |
| 61 | + TKUnit.waitUntilReady(() => completed, 5); |
| 62 | +} |
| 63 | + |
| 64 | +function waitUntilNavigatedFrom(action: Function, topFrame?: Frame) { |
| 65 | + const currentPage = topFrame ? topFrame.currentPage : Frame.topmost().currentPage; |
| 66 | + let completed = false; |
| 67 | + function navigatedFrom(args) { |
| 68 | + args.object.page.off("navigatedFrom", navigatedFrom); |
| 69 | + completed = true; |
| 70 | + } |
| 71 | + |
| 72 | + currentPage.on("navigatedFrom", navigatedFrom); |
| 73 | + action(); |
| 74 | + TKUnit.waitUntilReady(() => completed); |
| 75 | +} |
| 76 | + |
| 77 | +function waitUntilLayoutReady(view: View): void { |
| 78 | + TKUnit.waitUntilReady(() => view.isLayoutValid); |
| 79 | +} |
| 80 | + |
| 81 | +function navigateWithEntry(entry: NavigationEntry, topFrame?: Frame): Page { |
| 82 | + const page = Builder.createViewFromEntry(entry) as Page; |
| 83 | + entry.moduleName = null; |
| 84 | + entry.create = function () { |
| 85 | + return page; |
| 86 | + }; |
| 87 | + |
| 88 | + waitUntilNavigatedFrom(() => topFrame ? topFrame.navigate(entry) : Frame.topmost().navigate(entry)); |
| 89 | + // navigatedTo; |
| 90 | + // waitUntilNavigatedTo(() => topFrame ? topFrame.navigate(entry) : Frame.topmost().navigate(entry)); |
| 91 | + |
| 92 | + |
| 93 | + return page; |
| 94 | +} |
0 commit comments