| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0c8275f commit b113b00
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + <Frame defaultPage="ui-tests-app/main-page" /> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,11 @@ | |||
| 1 | - console.log("####### ------ APP MODULES START ") | ||
| 1 | + console.log("####### ------ APP MODULES START "); | ||
| 2 | 2 | ||
| 3 | 3 | import * as application from "tns-core-modules/application"; | |
| 4 | 4 | import * as trace from "tns-core-modules/trace"; | |
| 5 | + trace.addCategories(trace.categories.NativeLifecycle); | ||
| 6 | + trace.addCategories(trace.categories.Navigation); | ||
| 7 | + trace.addCategories(trace.categories.Transition); | ||
| 5 | 8 | trace.enable(); | |
| 6 | - trace.setCategories(trace.categories.concat( | ||
| 7 | - trace.categories.NativeLifecycle, | ||
| 8 | - trace.categories.Navigation, | ||
| 9 | - trace.categories.Transition | ||
| 10 | - )); | ||
| 11 | 9 | ||
| 12 | 10 | var countResume = 0; | |
| 13 | 11 | var countSuspend = 0; | |
@@ -25,7 +23,7 @@ application.on("uncaughtError", args => { | |||
| 25 | 23 | } | |
| 26 | 24 | }); | |
| 27 | 25 | ||
| 28 | - application.on(application.launchEvent, function (args: application.ApplicationEventData) { | ||
| 26 | + application.on(application.launchEvent, function(args: application.LaunchEventData) { | ||
| 29 | 27 | if (args.android) { | |
| 30 | 28 | // For Android applications, args.android is an android.content.Intent class. | |
| 31 | 29 | console.log("### Launched application with: " + args.android + "."); | |
@@ -35,7 +33,7 @@ application.on(application.launchEvent, function (args: application.ApplicationE | |||
| 35 | 33 | } | |
| 36 | 34 | }); | |
| 37 | 35 | ||
| 38 | - application.on(application.suspendEvent, function (args: application.ApplicationEventData) { | ||
| 36 | + application.on(application.suspendEvent, function(args: application.ApplicationEventData) { | ||
| 39 | 37 | if (args.android) { | |
| 40 | 38 | // For Android applications, args.android is an android activity class. | |
| 41 | 39 | console.log("#" + ++countSuspend + "# SuspendEvent Activity: " + args.android); | |
@@ -45,7 +43,7 @@ application.on(application.suspendEvent, function (args: application.Application | |||
| 45 | 43 | } | |
| 46 | 44 | }); | |
| 47 | 45 | ||
| 48 | - application.on(application.resumeEvent, function (args: application.ApplicationEventData) { | ||
| 46 | + application.on(application.resumeEvent, function(args: application.ApplicationEventData) { | ||
| 49 | 47 | if (args.android) { | |
| 50 | 48 | // For Android applications, args.android is an android activity class. | |
| 51 | 49 | console.log("#" + ++countResume + "# ResumeEvent Activity: " + args.android); | |
@@ -55,7 +53,7 @@ application.on(application.resumeEvent, function (args: application.ApplicationE | |||
| 55 | 53 | } | |
| 56 | 54 | }); | |
| 57 | 55 | ||
| 58 | - application.on(application.exitEvent, function (args: application.ApplicationEventData) { | ||
| 56 | + application.on(application.exitEvent, function(args: application.ApplicationEventData) { | ||
| 59 | 57 | if (args.android) { | |
| 60 | 58 | // For Android applications, args.android is an android activity class. | |
| 61 | 59 | console.log("### ExitEvent Activity: " + args.android); | |
@@ -65,7 +63,7 @@ application.on(application.exitEvent, function (args: application.ApplicationEve | |||
| 65 | 63 | } | |
| 66 | 64 | }); | |
| 67 | 65 | ||
| 68 | - application.on(application.lowMemoryEvent, function (args: application.ApplicationEventData) { | ||
| 66 | + application.on(application.lowMemoryEvent, function(args: application.ApplicationEventData) { | ||
| 69 | 67 | if (args.android) { | |
| 70 | 68 | // For Android applications, args.android is an android activity class. | |
| 71 | 69 | console.log("### LowMemoryEvent Activity: " + args.android); | |
@@ -75,12 +73,15 @@ application.on(application.lowMemoryEvent, function (args: application.Applicati | |||
| 75 | 73 | } | |
| 76 | 74 | }); | |
| 77 | 75 | ||
| 78 | - application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) { | ||
| 79 | - console.log("### NativeScriptError: " + args.error); | ||
| 80 | - console.log("### nativeException: " + (<any>args.error).nativeException); | ||
| 81 | - console.log("### stackTace: " + (<any>args.error).stackTrace); | ||
| 82 | - console.log("### stack: " + args.error.stack); | ||
| 76 | + application.on(application.uncaughtErrorEvent, function(args: application.UnhandledErrorEventData) { | ||
| 77 | + console.log("### NativeScriptError: " + args.error); | ||
| 78 | + console.log("### nativeException: " + (<any>args.error).nativeException); | ||
| 79 | + console.log("### stackTrace: " + (<any>args.error).stackTrace); | ||
| 80 | + console.log("### stack: " + args.error.stack); | ||
| 83 | 81 | }); | |
| 84 | 82 | ||
| 85 | 83 | application.setCssFileName("ui-tests-app/app.css"); | |
| 84 | + | ||
| 86 | 85 | application.start({ moduleName: "ui-tests-app/main-page" }); | |
| 86 | + // application.run({ moduleName: "ui-tests-app/app-root" }); | ||
| 87 | + // application.run(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -634,20 +634,12 @@ export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { | |||
| 634 | 634 | }; | |
| 635 | 635 | ||
| 636 | 636 | declare var Worker: any; | |
| 637 | - export var test_getString_WorksProperlyInWorker = function () { | ||
| 638 | - var ready; | ||
| 639 | - | ||
| 640 | - var worker = new Worker("./http-string-worker"); | ||
| 641 | - | ||
| 642 | - worker.onmessage = function (msg) { | ||
| 643 | - TKUnit.assert(typeof msg.data === "string", "Result from getString() should be valid string object!"); | ||
| 644 | - ready = true; | ||
| 645 | - } | ||
| 646 | - | ||
| 647 | - worker.onerror = function (e) { | ||
| 648 | - ready = true; | ||
| 649 | - throw e; | ||
| 650 | - } | ||
| 651 | - | ||
| 652 | - TKUnit.waitUntilReady(() => ready); | ||
| 653 | - } | ||
| 637 | + export var test_getString_WorksProperlyInWorker = function(done) { | ||
| 638 | + let worker = new Worker("./http-string-worker"); | ||
| 639 | + worker.onmessage = function(msg) { | ||
| 640 | + done(); | ||
| 641 | + }; | ||
| 642 | + worker.onerror = function(e) { | ||
| 643 | + done(e); | ||
| 644 | + }; | ||
| 645 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | require("globals"); | |
| 3 | 3 | ||
| 4 | 4 | import { Observable, EventData } from "../data/observable"; | |
| 5 | + // types | ||
| 6 | + import { View } from "../ui/core/view"; | ||
| 5 | 7 | import { | |
| 6 | 8 | trace as profilingTrace, | |
| 7 | 9 | time, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,8 @@ import { profile } from "../profiling"; | |||
| 13 | 13 | // First reexport so that app module is initialized. | |
| 14 | 14 | export * from "./application-common"; | |
| 15 | 15 | ||
| 16 | - import { NavigationEntry } from "../ui/frame"; | ||
| 16 | + // types | ||
| 17 | + import { NavigationEntry, View, AndroidActivityCallbacks } from "../ui/frame"; | ||
| 17 | 18 | ||
| 18 | 19 | const ActivityCreated = "activityCreated"; | |
| 19 | 20 | const ActivityDestroyed = "activityDestroyed"; | |
@@ -53,7 +54,7 @@ export class AndroidApplication extends Observable implements AndroidApplication | |||
| 53 | 54 | if (this.nativeApp === nativeApp) { | |
| 54 | 55 | return; | |
| 55 | 56 | } | |
| 56 | - | ||
| 57 | + | ||
| 57 | 58 | if (this.nativeApp) { | |
| 58 | 59 | throw new Error("application.android already initialized."); | |
| 59 | 60 | } | |
@@ -148,10 +149,35 @@ export function run(entry?: NavigationEntry | string) { | |||
| 148 | 149 | start(entry); | |
| 149 | 150 | } | |
| 150 | 151 | ||
| 152 | + const CALLBACKS = "_callbacks"; | ||
| 153 | + | ||
| 154 | + export function _resetRootView(entry?: NavigationEntry | string) { | ||
| 155 | + const activity = androidApp.foregroundActivity; | ||
| 156 | + if (!activity) { | ||
| 157 | + throw new Error("Cannot find android activity."); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + mainEntry = typeof entry === "string" ? { moduleName: entry } : entry; | ||
| 161 | + const callbacks: AndroidActivityCallbacks = activity[CALLBACKS]; | ||
| 162 | + callbacks.resetActivityContent(activity); | ||
| 163 | + } | ||
| 164 | + | ||
| 151 | 165 | export function getMainEntry() { | |
| 152 | 166 | return mainEntry; | |
| 153 | 167 | } | |
| 154 | 168 | ||
| 169 | + export function getRootView() { | ||
| 170 | + // Use start activity as a backup when foregroundActivity is still not set | ||
| 171 | + // in cases when we are getting the root view before activity.onResumed event is fired | ||
| 172 | + const activity = androidApp.foregroundActivity || androidApp.startActivity; | ||
| 173 | + if (!activity) { | ||
| 174 | + return undefined; | ||
| 175 | + } | ||
| 176 | + const callbacks: AndroidActivityCallbacks = activity[CALLBACKS]; | ||
| 177 | + | ||
| 178 | + return callbacks ? callbacks.getRootView() : undefined; | ||
| 179 | + } | ||
| 180 | + | ||
| 155 | 181 | export function getNativeApplication(): android.app.Application { | |
| 156 | 182 | // Try getting it from module - check whether application.android.init has been explicitly called | |
| 157 | 183 | let nativeApp = androidApp.nativeApp; | |
@@ -202,11 +228,11 @@ function initLifecycleCallbacks() { | |||
| 202 | 228 | } | |
| 203 | 229 | }); | |
| 204 | 230 | ||
| 205 | - const notifyActivityCreated = profile("notifyActivityCreated", function(activity: android.app.Activity, savedInstanceState: android.os.Bundle) { | ||
| 231 | + const notifyActivityCreated = profile("notifyActivityCreated", function (activity: android.app.Activity, savedInstanceState: android.os.Bundle) { | ||
| 206 | 232 | androidApp.notify(<AndroidActivityBundleEventData>{ eventName: ActivityCreated, object: androidApp, activity, bundle: savedInstanceState }); | |
| 207 | 233 | }); | |
| 208 | 234 | ||
| 209 | - const subscribeForGlobalLayout = profile("subscribeForGlobalLayout", function(activity: android.app.Activity) { | ||
| 235 | + const subscribeForGlobalLayout = profile("subscribeForGlobalLayout", function (activity: android.app.Activity) { | ||
| 210 | 236 | const rootView = activity.getWindow().getDecorView().getRootView(); | |
| 211 | 237 | let onGlobalLayoutListener = new android.view.ViewTreeObserver.OnGlobalLayoutListener({ | |
| 212 | 238 | onGlobalLayout() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,11 @@ export interface CssChangedEventData extends EventData { | |||
| 116 | 116 | */ | |
| 117 | 117 | export function getMainEntry(): NavigationEntry; | |
| 118 | 118 | ||
| 119 | + /** | ||
| 120 | + * Get current application root view. | ||
| 121 | + */ | ||
| 122 | + export function getRootView(): View; | ||
| 123 | + | ||
| 119 | 124 | /** | |
| 120 | 125 | * Get application level static resources. | |
| 121 | 126 | */ | |
@@ -178,6 +183,12 @@ export function start(entry?: NavigationEntry | string); | |||
| 178 | 183 | */ | |
| 179 | 184 | export function run(entry?: NavigationEntry | string); | |
| 180 | 185 | ||
| 186 | + /** | ||
| 187 | + * Call this method to change the root view of your application. Important: Your application must already be running. | ||
| 188 | + * This method won't create Frame as root view. | ||
| 189 | + */ | ||
| 190 | + export function _resetRootView(entry?: NavigationEntry | string); | ||
| 191 | + | ||
| 181 | 192 | //@private | |
| 182 | 193 | /** | |
| 183 | 194 | * Internal method use to check if a root Frame should be automatically created as root view. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,10 @@ class IOSApplication implements IOSApplicationDefinition { | |||
| 100 | 100 | } | |
| 101 | 101 | } | |
| 102 | 102 | ||
| 103 | + get rootView() : View { | ||
| 104 | + return this._rootView; | ||
| 105 | + } | ||
| 106 | + | ||
| 103 | 107 | public addNotificationObserver(notificationName: string, onReceiveCallback: (notification: NSNotification) => void): NotificationObserver { | |
| 104 | 108 | const observer = NotificationObserver.initWithCallback(onReceiveCallback); | |
| 105 | 109 | utils.ios.getter(NSNotificationCenter, NSNotificationCenter.defaultCenter).addObserverSelectorNameObject(observer, "onReceive", notificationName, null); | |
@@ -263,6 +267,10 @@ export function getMainEntry() { | |||
| 263 | 267 | return mainEntry; | |
| 264 | 268 | } | |
| 265 | 269 | ||
| 270 | + export function getRootView() { | ||
| 271 | + return iosApp.rootView; | ||
| 272 | + } | ||
| 273 | + | ||
| 266 | 274 | // NOTE: for backwards compatibility. Remove for 4.0.0. | |
| 267 | 275 | let createRootFrame = true; | |
| 268 | 276 | let started: boolean = false; | |
@@ -296,6 +304,12 @@ export function run(entry?: string | NavigationEntry) { | |||
| 296 | 304 | start(entry); | |
| 297 | 305 | } | |
| 298 | 306 | ||
| 307 | + export function _resetRootView(entry?: NavigationEntry | string) { | ||
| 308 | + createRootFrame = false; | ||
| 309 | + mainEntry = typeof entry === "string" ? { moduleName: entry } : entry; | ||
| 310 | + iosApp.setWindowContent(); | ||
| 311 | + } | ||
| 312 | + | ||
| 299 | 313 | export function getNativeApplication(): UIApplication { | |
| 300 | 314 | return iosApp.nativeApp; | |
| 301 | 315 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | // Definitions. | |
| 2 | 2 | import { LoadOptions } from "."; | |
| 3 | 3 | import { View, ViewBase, Template, KeyedTemplate } from "../core/view"; | |
| 4 | - import { NavigationEntry } from "../frame"; | ||
| 4 | + import { ViewEntry } from "../frame"; | ||
| 5 | 5 | ||
| 6 | 6 | // Types. | |
| 7 | 7 | import { debug, ScopeError, SourceError, Source } from "../../utils/debug"; | |
@@ -62,7 +62,7 @@ export function loadPage(moduleNamePath: string, fileName: string, context?: any | |||
| 62 | 62 | return componentModule && componentModule.component; | |
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | - const loadModule = profile("loadModule", (moduleNamePath: string, entry: NavigationEntry): ModuleExports => { | ||
| 65 | + const loadModule = profile("loadModule", (moduleNamePath: string, entry: ViewEntry): ModuleExports => { | ||
| 66 | 66 | // web-pack case where developers register their page JS file manually. | |
| 67 | 67 | if (global.moduleExists(entry.moduleName)) { | |
| 68 | 68 | return global.loadModule(entry.moduleName); | |
@@ -94,7 +94,7 @@ const viewFromBuilder = profile("viewFromBuilder", (moduleNamePath: string, modu | |||
| 94 | 94 | return null; | |
| 95 | 95 | }) | |
| 96 | 96 | ||
| 97 | - export const createViewFromEntry = profile("createViewFromEntry", (entry: NavigationEntry): View => { | ||
| 97 | + export const createViewFromEntry = profile("createViewFromEntry", (entry: ViewEntry): View => { | ||
| 98 | 98 | if (entry.create) { | |
| 99 | 99 | return createView(entry); | |
| 100 | 100 | } else if (entry.moduleName) { | |
@@ -116,7 +116,7 @@ export const createViewFromEntry = profile("createViewFromEntry", (entry: Naviga | |||
| 116 | 116 | throw new Error("Failed to load page XML file for module: " + entry.moduleName); | |
| 117 | 117 | }); | |
| 118 | 118 | ||
| 119 | - const createView = profile("entry.create", (entry: NavigationEntry): View => { | ||
| 119 | + const createView = profile("entry.create", (entry: ViewEntry): View => { | ||
| 120 | 120 | const view = entry.create(); | |
| 121 | 121 | if (!view) { | |
| 122 | 122 | throw new Error("Failed to create Page with entry.create() function."); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ class NativeScriptActivity extends android.app.Activity { | |||
| 19 | 19 | appModule.android.init(this.getApplication()); | |
| 20 | 20 | ||
| 21 | 21 | // Set isNativeScriptActivity in onCreate. | |
| 22 | - // The JS construcotr might not be called beacuse the activity is created from Andoird. | ||
| 22 | + // The JS constructor might not be called because the activity is created from Android. | ||
| 23 | 23 | this.isNativeScriptActivity = true; | |
| 24 | 24 | if (!this._callbacks) { | |
| 25 | 25 | setActivityCallbacks(this); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments