From a8be5034170dfbb8c5a6841a0e17920e8d613f1c Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Mon, 1 Jun 2015 15:51:37 +0300 Subject: [PATCH] various application event implementation fixes --- application/application-common.ts | 12 +++++++++++ application/application.android.ts | 10 ++++----- application/application.d.ts | 34 ++++++++++++++++++++++++++++-- application/application.ios.ts | 12 +++++------ apps/tests/app/app.ts | 26 ++++++++++++----------- ui/frame/frame.android.ts | 2 +- 6 files changed, 70 insertions(+), 26 deletions(-) diff --git a/application/application-common.ts b/application/application-common.ts index e6a460936..379bcbc2d 100644 --- a/application/application-common.ts +++ b/application/application-common.ts @@ -8,6 +8,18 @@ import observable = require("data/observable"); var events = new observable.Observable(); require("utils/module-merge").merge(events, exports); +export var launch = "launch"; + +export var uncaughtError = "uncaughtError"; + +export var suspend = "suspend"; + +export var resume = "resume"; + +export var exit = "exit"; + +export var lowMemory = "lowMemory"; + export var cssFile: string = "app.css" export var resources: any = {}; diff --git a/application/application.android.ts b/application/application.android.ts index a535cf63a..41e24c7a3 100644 --- a/application/application.android.ts +++ b/application/application.android.ts @@ -44,7 +44,7 @@ var initEvents = function () { exports.onExit(); } - exports.notify({ eventName: "onExit", object: androidApp, android: activity, ios: undefined }); + exports.notify({ eventName: dts.exit, object: androidApp, android: activity }); androidApp.startActivity = undefined; } @@ -62,7 +62,7 @@ var initEvents = function () { exports.onSuspend(); } - exports.notify({ eventName: "onSuspend", object: androidApp, android: activity, ios: undefined }); + exports.notify({ eventName: dts.suspend, object: androidApp, android: activity }); } @@ -76,7 +76,7 @@ var initEvents = function () { exports.onResume(); } - exports.notify({ eventName: "onResume", object: androidApp, android: activity, ios: undefined }); + exports.notify({ eventName: dts.resume, object: androidApp, android: activity }); } @@ -192,7 +192,7 @@ class AndroidApplication implements dts.AndroidApplication { exports.onLaunch(intent); } - exports.notify({ eventName: "onLaunch", object: this, android: intent, ios: undefined }); + exports.notify({ eventName: dts.launch, object: this, android: intent }); /* In the onLaunch event we expect the following setup, which ensures a root frame: * var frame = require("ui/frame"); @@ -236,7 +236,7 @@ global.__onUncaughtError = function (error: Error) { exports.onUncaughtError(nsError); - exports.notify({ eventName: "onUncaughtError", object: appModule.android, android: error, ios: undefined }); + exports.notify({ eventName: dts.uncaughtError, object: appModule.android, android: error }); } exports.start = function () { diff --git a/application/application.d.ts b/application/application.d.ts index 352d52276..9d7e59a71 100644 --- a/application/application.d.ts +++ b/application/application.d.ts @@ -15,6 +15,36 @@ declare module "application" { nativeError: any; } + /** + * String value used when hooking to launch event. + */ + export var launch: string; + + /** + * String value used when hooking to uncaughtError event. + */ + export var uncaughtError: string; + + /** + * String value used when hooking to suspend event. + */ + export var suspend: string; + + /** + * String value used when hooking to resume event. + */ + export var resume: string; + + /** + * String value used when hooking to exit event. + */ + export var exit: string; + + /** + * String value used when hooking to lowMemory event. + */ + export var lowMemory: string; + /** * Event data containing information for the application events. */ @@ -22,12 +52,12 @@ declare module "application" { /** * Gets the native iOS event arguments. Valid only when running on iOS. */ - ios: any; + ios?: any; /** * Gets the native Android event arguments. Valid only when running on Android. */ - android: any; + android?: any; } /** diff --git a/application/application.ios.ts b/application/application.ios.ts index f4ffd6866..56e1011bf 100644 --- a/application/application.ios.ts +++ b/application/application.ios.ts @@ -50,7 +50,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate { exports.onLaunch(); } - exports.notify({ eventName: "onLaunch", object: this, android: undefined, ios: launchOptions }); + exports.notify({ eventName: definition.launch, object: this, ios: launchOptions }); var topFrame = frame.topmost(); if (!topFrame) { @@ -77,7 +77,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate { exports.onResume(); } - exports.notify({ eventName: "onResume", object: this, android: undefined, ios: application }); + exports.notify({ eventName: definition.resume, object: this, ios: application }); } applicationWillResignActive(application: UIApplication) { @@ -89,7 +89,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate { exports.onSuspend(); } - exports.notify({ eventName: "onSuspend", object: this, android: undefined, ios: application }); + exports.notify({ eventName: definition.suspend, object: this, ios: application }); } applicationWillEnterForeground(application: UIApplication) { @@ -101,7 +101,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate { exports.onExit(); } - exports.notify({ eventName: "onExit", object: this, android: undefined, ios: application }); + exports.notify({ eventName: definition.exit, object: this, ios: application }); } applicationDidReceiveMemoryWarning(application: UIApplication) { @@ -109,7 +109,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate { exports.onLowMemory(); } - exports.notify({ eventName: "onLowMemory", object: this, android: undefined, ios: application }); + exports.notify({ eventName: definition.lowMemory, object: this, android: undefined, ios: application }); } applicationOpenURLSourceApplicationAnnotation(application: UIApplication, url: NSURL, sourceApplication: string, annotation: any): boolean { @@ -158,6 +158,6 @@ exports.start = function () { exports.onUncaughtError(error); - definition.notify({ eventName: "onUncaughtError", object: definition.ios, android: undefined, ios: error }); + definition.notify({ eventName: definition.uncaughtError, object: definition.ios, ios: error }); } } \ No newline at end of file diff --git a/apps/tests/app/app.ts b/apps/tests/app/app.ts index 62b564eba..999c76e75 100644 --- a/apps/tests/app/app.ts +++ b/apps/tests/app/app.ts @@ -1,28 +1,30 @@ import application = require("application"); application.mainModule = "app/mainPage"; -application.on("onLaunch", function (args) { - console.log("onLaunch: " + args); +application.on(application.launch, function (args: application.ApplicationEventData) { + console.log("launch, iOS: " + args.ios + ", Android: " + args.android); }); -application.on("onUncaughtError", function (args) { - console.log("onUncaughtError: " + args); +application.on(application.uncaughtError, function (args: application.ApplicationEventData) { + console.log("uncaughtError, iOS: " + args.ios + ", Android: " + args.android); }); -application.on("onSuspend", function (args) { - console.log("onSuspend: " + args); +application.on(application.suspend, function (args: application.ApplicationEventData) { + console.log("suspend, iOS: " + args.ios + ", Android: " + args.android); + }); -application.on("onResume", function (args) { - console.log("onResume: " + args); +application.on(application.resume, function (args: application.ApplicationEventData) { + console.log("resume, iOS: " + args.ios + ", Android: " + args.android); }); -application.on("onExit", function (args) { - console.log("onExit: " + args); +application.on(application.exit, function (args: application.ApplicationEventData) { + console.log("exit, iOS: " + args.ios + ", Android: " + args.android); }); -application.on("onLowMemory", function (args) { - console.log("onLowMemory: " + args); +application.on(application.lowMemory, function (args: application.ApplicationEventData) { + console.log("exit, iOS: " + args.ios + ", Android: " + args.android); + }); application.start(); diff --git a/ui/frame/frame.android.ts b/ui/frame/frame.android.ts index 570df03ad..39868a495 100644 --- a/ui/frame/frame.android.ts +++ b/ui/frame/frame.android.ts @@ -495,7 +495,7 @@ var NativeActivity = { java.lang.System.gc(); this.super.onLowMemory(); - application.notify({ eventName: "onLowMemory", object: this, android: undefined, ios: undefined }); + application.notify({ eventName: application.lowMemory, object: this }); }, onTrimMemory: function (level: number) {