mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Added some application implementation for Android. Updated the fields of the iOS-specific application.
This commit is contained in:
@ -6,8 +6,12 @@ require("utils/module-merge").merge(appModule, exports);
|
||||
|
||||
var callbacks = android.app.Application.ActivityLifecycleCallbacks;
|
||||
|
||||
// We are using the exports object for the common events since we merge the appModule with this module's exports, which is what users will receive when require("application") is called;
|
||||
// TODO: This is kind of hacky and is "pure JS in TypeScript"
|
||||
|
||||
var initEvents = function () {
|
||||
var androidApp = exports.android;
|
||||
var androidApp: AndroidApplication = exports.android;
|
||||
// TODO: Verify whether the logic for triggerring application-wide events based on Activity callbacks is working properly
|
||||
var lifecycleCallbacks = new callbacks({
|
||||
onActivityCreated: function (activity: any, bundle: any) {
|
||||
if (!androidApp.startActivity) {
|
||||
@ -24,34 +28,33 @@ var initEvents = function () {
|
||||
androidApp.currentActivity = undefined;
|
||||
}
|
||||
|
||||
//if (activity === UI.Application.android.startActivity) {
|
||||
// UI.Application.android.currentActivity = undefined;
|
||||
// if (UI.Application.current.onExit) {
|
||||
// UI.Application.current.onExit();
|
||||
// }
|
||||
//}
|
||||
if (activity === androidApp.startActivity) {
|
||||
if (exports.onExit) {
|
||||
exports.onExit();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityDestroyed) {
|
||||
androidApp.onActivityDestroyed(activity);
|
||||
}
|
||||
},
|
||||
onActivityPaused: function (activity: any) {
|
||||
//if (UI.Application.android.currentActivity === activity) {
|
||||
// if (UI.Application.current.onSuspend) {
|
||||
// UI.Application.current.onSuspend();
|
||||
// }
|
||||
//}
|
||||
if (activity === androidApp.currentActivity) {
|
||||
if (exports.onSuspend) {
|
||||
exports.onSuspend();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityPaused) {
|
||||
androidApp.onActivityPaused(activity);
|
||||
}
|
||||
},
|
||||
onActivityResumed: function (activity: any) {
|
||||
//if (UI.Application.android.currentActivity === activity) {
|
||||
// if (UI.Application.current.onResume) {
|
||||
// UI.Application.current.onResume();
|
||||
// }
|
||||
//}
|
||||
if (activity === androidApp.currentActivity) {
|
||||
if (exports.onResume) {
|
||||
exports.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
if (androidApp.onActivityResumed) {
|
||||
androidApp.onActivityResumed(activity);
|
||||
@ -65,12 +68,6 @@ var initEvents = function () {
|
||||
onActivityStarted: function (activity: any) {
|
||||
androidApp.currentActivity = activity;
|
||||
|
||||
//if (activity === UI.Application.android.startActivity) {
|
||||
// if (UI.Application.current.onStart) {
|
||||
// UI.Application.current.onStart();
|
||||
// }
|
||||
//}
|
||||
|
||||
if (androidApp.onActivityStarted) {
|
||||
androidApp.onActivityStarted(activity);
|
||||
}
|
||||
@ -105,13 +102,13 @@ class AndroidApplication {
|
||||
public startActivity: android.app.Activity;
|
||||
public packageName: string;
|
||||
|
||||
public onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => any;
|
||||
public onActivityDestroyed: (activity: android.app.Activity) => any;
|
||||
public onActivityStarted: (activity: android.app.Activity) => any;
|
||||
public onActivityPaused: (activity: android.app.Activity) => any;
|
||||
public onActivityResumed: (activity: android.app.Activity) => any;
|
||||
public onActivityStopped: (activity: android.app.Activity) => any;
|
||||
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => any;
|
||||
public onActivityCreated: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
|
||||
public onActivityDestroyed: (activity: android.app.Activity) => void;
|
||||
public onActivityStarted: (activity: android.app.Activity) => void;
|
||||
public onActivityPaused: (activity: android.app.Activity) => void;
|
||||
public onActivityResumed: (activity: android.app.Activity) => void;
|
||||
public onActivityStopped: (activity: android.app.Activity) => void;
|
||||
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
|
||||
|
||||
private _eventsToken: any;
|
||||
|
||||
|
@ -44,10 +44,13 @@ class iOSApplication {
|
||||
public rootController: any;
|
||||
|
||||
constructor(nativeApp: any) {
|
||||
this.nativeApp = nativeApp;
|
||||
// TODO: in iOS there is the singleton instance, while in Android such does not exist hence we pass it as argument
|
||||
// this.nativeApp = nativeApp;
|
||||
this.nativeApp = UIKit.UIApplication.sharedApplication();
|
||||
}
|
||||
|
||||
public init() {
|
||||
var that = this;
|
||||
UIKit.UIResponder.extends({/*TODO: Empty parameter here, needs API improvement*/}, {
|
||||
name: "TNSAppDelegate",
|
||||
}).implements({
|
||||
@ -61,7 +64,9 @@ class iOSApplication {
|
||||
this.window.makeKeyAndVisible();
|
||||
|
||||
if (exports.onLaunch) {
|
||||
this.window.rootViewController = exports.onLaunch();
|
||||
that.rootController = exports.onLaunch();
|
||||
this.window.rootViewController = that.rootController;
|
||||
|
||||
} else {
|
||||
log("Missing Application.onLaunch");
|
||||
}
|
||||
|
Reference in New Issue
Block a user