mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(Application): inBackground handling & missing once (#10307)
This commit is contained in:
@@ -128,6 +128,7 @@ export class ApplicationCommon {
|
||||
|
||||
// Application events go through the global events.
|
||||
on: ApplicationEvents['on'] = globalEvents.on.bind(globalEvents);
|
||||
once: ApplicationEvents['on'] = globalEvents.once.bind(globalEvents);
|
||||
off: ApplicationEvents['off'] = globalEvents.off.bind(globalEvents);
|
||||
notify: ApplicationEvents['notify'] = globalEvents.notify.bind(globalEvents);
|
||||
hasListeners: ApplicationEvents['hasListeners'] = globalEvents.hasListeners.bind(globalEvents);
|
||||
|
||||
@@ -138,11 +138,11 @@ class NativeScriptLifecycleCallbacks extends android.app.Application.ActivityLif
|
||||
|
||||
this.activitiesCount++;
|
||||
if (this.activitiesCount === 1) {
|
||||
Application.android.notify({
|
||||
eventName: Application.foregroundEvent,
|
||||
object: Application.android,
|
||||
Application.android.setInBackground(false, {
|
||||
// todo: deprecate event.android in favor of event.activity
|
||||
android: activity,
|
||||
} as ApplicationEventData);
|
||||
activity,
|
||||
});
|
||||
}
|
||||
|
||||
Application.android.notify({
|
||||
@@ -157,11 +157,11 @@ class NativeScriptLifecycleCallbacks extends android.app.Application.ActivityLif
|
||||
// console.log('NativeScriptLifecycleCallbacks onActivityStopped');
|
||||
this.activitiesCount--;
|
||||
if (this.activitiesCount === 0) {
|
||||
Application.android.notify({
|
||||
eventName: Application.backgroundEvent,
|
||||
object: Application.android,
|
||||
Application.android.setInBackground(true, {
|
||||
// todo: deprecate event.android in favor of event.activity
|
||||
android: activity,
|
||||
} as ApplicationEventData);
|
||||
activity,
|
||||
});
|
||||
}
|
||||
|
||||
Application.android.notify({
|
||||
|
||||
@@ -98,6 +98,7 @@ global.CFRunLoopWakeUp = function (runloop) {};
|
||||
global.NativeScriptGlobals = {
|
||||
events: {
|
||||
on: (args) => {},
|
||||
once: (args) => {},
|
||||
off: (args) => {},
|
||||
notify: (args) => {},
|
||||
hasListeners: (args) => {},
|
||||
|
||||
Reference in New Issue
Block a user