mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
various application event implementation fixes
This commit is contained in:
@ -8,6 +8,18 @@ import observable = require("data/observable");
|
|||||||
var events = new observable.Observable();
|
var events = new observable.Observable();
|
||||||
require("utils/module-merge").merge(events, exports);
|
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 cssFile: string = "app.css"
|
||||||
|
|
||||||
export var resources: any = {};
|
export var resources: any = {};
|
||||||
|
@ -44,7 +44,7 @@ var initEvents = function () {
|
|||||||
exports.onExit();
|
exports.onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.notify({ eventName: "onExit", object: androidApp, android: activity, ios: undefined });
|
exports.notify({ eventName: dts.exit, object: androidApp, android: activity });
|
||||||
|
|
||||||
androidApp.startActivity = undefined;
|
androidApp.startActivity = undefined;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ var initEvents = function () {
|
|||||||
exports.onSuspend();
|
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.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.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:
|
/* In the onLaunch event we expect the following setup, which ensures a root frame:
|
||||||
* var frame = require("ui/frame");
|
* var frame = require("ui/frame");
|
||||||
@ -236,7 +236,7 @@ global.__onUncaughtError = function (error: Error) {
|
|||||||
|
|
||||||
exports.onUncaughtError(nsError);
|
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 () {
|
exports.start = function () {
|
||||||
|
34
application/application.d.ts
vendored
34
application/application.d.ts
vendored
@ -15,6 +15,36 @@ declare module "application" {
|
|||||||
nativeError: any;
|
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.
|
* 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.
|
* 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.
|
* Gets the native Android event arguments. Valid only when running on Android.
|
||||||
*/
|
*/
|
||||||
android: any;
|
android?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
|
|||||||
exports.onLaunch();
|
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();
|
var topFrame = frame.topmost();
|
||||||
if (!topFrame) {
|
if (!topFrame) {
|
||||||
@ -77,7 +77,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
|
|||||||
exports.onResume();
|
exports.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.notify({ eventName: "onResume", object: this, android: undefined, ios: application });
|
exports.notify({ eventName: definition.resume, object: this, ios: application });
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationWillResignActive(application: UIApplication) {
|
applicationWillResignActive(application: UIApplication) {
|
||||||
@ -89,7 +89,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
|
|||||||
exports.onSuspend();
|
exports.onSuspend();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.notify({ eventName: "onSuspend", object: this, android: undefined, ios: application });
|
exports.notify({ eventName: definition.suspend, object: this, ios: application });
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationWillEnterForeground(application: UIApplication) {
|
applicationWillEnterForeground(application: UIApplication) {
|
||||||
@ -101,7 +101,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
|
|||||||
exports.onExit();
|
exports.onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.notify({ eventName: "onExit", object: this, android: undefined, ios: application });
|
exports.notify({ eventName: definition.exit, object: this, ios: application });
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationDidReceiveMemoryWarning(application: UIApplication) {
|
applicationDidReceiveMemoryWarning(application: UIApplication) {
|
||||||
@ -109,7 +109,7 @@ class TNSAppDelegate extends UIResponder implements UIApplicationDelegate {
|
|||||||
exports.onLowMemory();
|
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 {
|
applicationOpenURLSourceApplicationAnnotation(application: UIApplication, url: NSURL, sourceApplication: string, annotation: any): boolean {
|
||||||
@ -158,6 +158,6 @@ exports.start = function () {
|
|||||||
|
|
||||||
exports.onUncaughtError(error);
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,28 +1,30 @@
|
|||||||
import application = require("application");
|
import application = require("application");
|
||||||
application.mainModule = "app/mainPage";
|
application.mainModule = "app/mainPage";
|
||||||
|
|
||||||
application.on("onLaunch", function (args) {
|
application.on(application.launch, function (args: application.ApplicationEventData) {
|
||||||
console.log("onLaunch: " + args);
|
console.log("launch, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
});
|
});
|
||||||
|
|
||||||
application.on("onUncaughtError", function (args) {
|
application.on(application.uncaughtError, function (args: application.ApplicationEventData) {
|
||||||
console.log("onUncaughtError: " + args);
|
console.log("uncaughtError, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
});
|
});
|
||||||
|
|
||||||
application.on("onSuspend", function (args) {
|
application.on(application.suspend, function (args: application.ApplicationEventData) {
|
||||||
console.log("onSuspend: " + args);
|
console.log("suspend, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
application.on("onResume", function (args) {
|
application.on(application.resume, function (args: application.ApplicationEventData) {
|
||||||
console.log("onResume: " + args);
|
console.log("resume, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
});
|
});
|
||||||
|
|
||||||
application.on("onExit", function (args) {
|
application.on(application.exit, function (args: application.ApplicationEventData) {
|
||||||
console.log("onExit: " + args);
|
console.log("exit, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
});
|
});
|
||||||
|
|
||||||
application.on("onLowMemory", function (args) {
|
application.on(application.lowMemory, function (args: application.ApplicationEventData) {
|
||||||
console.log("onLowMemory: " + args);
|
console.log("exit, iOS: " + args.ios + ", Android: " + args.android);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
application.start();
|
application.start();
|
||||||
|
@ -495,7 +495,7 @@ var NativeActivity = {
|
|||||||
java.lang.System.gc();
|
java.lang.System.gc();
|
||||||
this.super.onLowMemory();
|
this.super.onLowMemory();
|
||||||
|
|
||||||
application.notify(<application.ApplicationEventData>{ eventName: "onLowMemory", object: this, android: undefined, ios: undefined });
|
application.notify(<application.ApplicationEventData>{ eventName: application.lowMemory, object: this });
|
||||||
},
|
},
|
||||||
|
|
||||||
onTrimMemory: function (level: number) {
|
onTrimMemory: function (level: number) {
|
||||||
|
Reference in New Issue
Block a user