various application event implementation fixes

This commit is contained in:
Vladimir Enchev
2015-06-01 15:51:37 +03:00
parent c6549343bc
commit a8be503417
6 changed files with 70 additions and 26 deletions

View File

@ -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 = {};

View File

@ -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 () {

View File

@ -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;
}
/**

View File

@ -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: <any>definition.ios, android: undefined, ios: error });
definition.notify({ eventName: definition.uncaughtError, object: <any>definition.ios, ios: error });
}
}