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;
|
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 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({
|
var lifecycleCallbacks = new callbacks({
|
||||||
onActivityCreated: function (activity: any, bundle: any) {
|
onActivityCreated: function (activity: any, bundle: any) {
|
||||||
if (!androidApp.startActivity) {
|
if (!androidApp.startActivity) {
|
||||||
@ -24,34 +28,33 @@ var initEvents = function () {
|
|||||||
androidApp.currentActivity = undefined;
|
androidApp.currentActivity = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (activity === UI.Application.android.startActivity) {
|
if (activity === androidApp.startActivity) {
|
||||||
// UI.Application.android.currentActivity = undefined;
|
if (exports.onExit) {
|
||||||
// if (UI.Application.current.onExit) {
|
exports.onExit();
|
||||||
// UI.Application.current.onExit();
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
if (androidApp.onActivityDestroyed) {
|
if (androidApp.onActivityDestroyed) {
|
||||||
androidApp.onActivityDestroyed(activity);
|
androidApp.onActivityDestroyed(activity);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onActivityPaused: function (activity: any) {
|
onActivityPaused: function (activity: any) {
|
||||||
//if (UI.Application.android.currentActivity === activity) {
|
if (activity === androidApp.currentActivity) {
|
||||||
// if (UI.Application.current.onSuspend) {
|
if (exports.onSuspend) {
|
||||||
// UI.Application.current.onSuspend();
|
exports.onSuspend();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (androidApp.onActivityPaused) {
|
if (androidApp.onActivityPaused) {
|
||||||
androidApp.onActivityPaused(activity);
|
androidApp.onActivityPaused(activity);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onActivityResumed: function (activity: any) {
|
onActivityResumed: function (activity: any) {
|
||||||
//if (UI.Application.android.currentActivity === activity) {
|
if (activity === androidApp.currentActivity) {
|
||||||
// if (UI.Application.current.onResume) {
|
if (exports.onResume) {
|
||||||
// UI.Application.current.onResume();
|
exports.onResume();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (androidApp.onActivityResumed) {
|
if (androidApp.onActivityResumed) {
|
||||||
androidApp.onActivityResumed(activity);
|
androidApp.onActivityResumed(activity);
|
||||||
@ -65,12 +68,6 @@ var initEvents = function () {
|
|||||||
onActivityStarted: function (activity: any) {
|
onActivityStarted: function (activity: any) {
|
||||||
androidApp.currentActivity = activity;
|
androidApp.currentActivity = activity;
|
||||||
|
|
||||||
//if (activity === UI.Application.android.startActivity) {
|
|
||||||
// if (UI.Application.current.onStart) {
|
|
||||||
// UI.Application.current.onStart();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (androidApp.onActivityStarted) {
|
if (androidApp.onActivityStarted) {
|
||||||
androidApp.onActivityStarted(activity);
|
androidApp.onActivityStarted(activity);
|
||||||
}
|
}
|
||||||
@ -105,13 +102,13 @@ class AndroidApplication {
|
|||||||
public startActivity: android.app.Activity;
|
public startActivity: android.app.Activity;
|
||||||
public packageName: string;
|
public packageName: string;
|
||||||
|
|
||||||
public onActivityCreated: (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) => any;
|
public onActivityDestroyed: (activity: android.app.Activity) => void;
|
||||||
public onActivityStarted: (activity: android.app.Activity) => any;
|
public onActivityStarted: (activity: android.app.Activity) => void;
|
||||||
public onActivityPaused: (activity: android.app.Activity) => any;
|
public onActivityPaused: (activity: android.app.Activity) => void;
|
||||||
public onActivityResumed: (activity: android.app.Activity) => any;
|
public onActivityResumed: (activity: android.app.Activity) => void;
|
||||||
public onActivityStopped: (activity: android.app.Activity) => any;
|
public onActivityStopped: (activity: android.app.Activity) => void;
|
||||||
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => any;
|
public onSaveActivityState: (activity: android.app.Activity, bundle: android.os.Bundle) => void;
|
||||||
|
|
||||||
private _eventsToken: any;
|
private _eventsToken: any;
|
||||||
|
|
||||||
|
@ -44,10 +44,13 @@ class iOSApplication {
|
|||||||
public rootController: any;
|
public rootController: any;
|
||||||
|
|
||||||
constructor(nativeApp: 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() {
|
public init() {
|
||||||
|
var that = this;
|
||||||
UIKit.UIResponder.extends({/*TODO: Empty parameter here, needs API improvement*/}, {
|
UIKit.UIResponder.extends({/*TODO: Empty parameter here, needs API improvement*/}, {
|
||||||
name: "TNSAppDelegate",
|
name: "TNSAppDelegate",
|
||||||
}).implements({
|
}).implements({
|
||||||
@ -61,7 +64,9 @@ class iOSApplication {
|
|||||||
this.window.makeKeyAndVisible();
|
this.window.makeKeyAndVisible();
|
||||||
|
|
||||||
if (exports.onLaunch) {
|
if (exports.onLaunch) {
|
||||||
this.window.rootViewController = exports.onLaunch();
|
that.rootController = exports.onLaunch();
|
||||||
|
this.window.rootViewController = that.rootController;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log("Missing Application.onLaunch");
|
log("Missing Application.onLaunch");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user