fix(Application): inBackground handling & missing once (#10307)

This commit is contained in:
Igor Randjelovic
2023-06-14 22:09:41 +02:00
committed by GitHub
parent b50812f724
commit e430555cb2
3 changed files with 10 additions and 8 deletions

View File

@@ -128,6 +128,7 @@ export class ApplicationCommon {
// Application events go through the global events. // Application events go through the global events.
on: ApplicationEvents['on'] = globalEvents.on.bind(globalEvents); on: ApplicationEvents['on'] = globalEvents.on.bind(globalEvents);
once: ApplicationEvents['on'] = globalEvents.once.bind(globalEvents);
off: ApplicationEvents['off'] = globalEvents.off.bind(globalEvents); off: ApplicationEvents['off'] = globalEvents.off.bind(globalEvents);
notify: ApplicationEvents['notify'] = globalEvents.notify.bind(globalEvents); notify: ApplicationEvents['notify'] = globalEvents.notify.bind(globalEvents);
hasListeners: ApplicationEvents['hasListeners'] = globalEvents.hasListeners.bind(globalEvents); hasListeners: ApplicationEvents['hasListeners'] = globalEvents.hasListeners.bind(globalEvents);

View File

@@ -138,11 +138,11 @@ class NativeScriptLifecycleCallbacks extends android.app.Application.ActivityLif
this.activitiesCount++; this.activitiesCount++;
if (this.activitiesCount === 1) { if (this.activitiesCount === 1) {
Application.android.notify({ Application.android.setInBackground(false, {
eventName: Application.foregroundEvent, // todo: deprecate event.android in favor of event.activity
object: Application.android,
android: activity, android: activity,
} as ApplicationEventData); activity,
});
} }
Application.android.notify({ Application.android.notify({
@@ -157,11 +157,11 @@ class NativeScriptLifecycleCallbacks extends android.app.Application.ActivityLif
// console.log('NativeScriptLifecycleCallbacks onActivityStopped'); // console.log('NativeScriptLifecycleCallbacks onActivityStopped');
this.activitiesCount--; this.activitiesCount--;
if (this.activitiesCount === 0) { if (this.activitiesCount === 0) {
Application.android.notify({ Application.android.setInBackground(true, {
eventName: Application.backgroundEvent, // todo: deprecate event.android in favor of event.activity
object: Application.android,
android: activity, android: activity,
} as ApplicationEventData); activity,
});
} }
Application.android.notify({ Application.android.notify({

View File

@@ -98,6 +98,7 @@ global.CFRunLoopWakeUp = function (runloop) {};
global.NativeScriptGlobals = { global.NativeScriptGlobals = {
events: { events: {
on: (args) => {}, on: (args) => {},
once: (args) => {},
off: (args) => {}, off: (args) => {},
notify: (args) => {}, notify: (args) => {},
hasListeners: (args) => {}, hasListeners: (args) => {},