From e430555cb24650ff1500867fefb86928d148d7f7 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 14 Jun 2023 22:09:41 +0200 Subject: [PATCH] fix(Application): inBackground handling & missing `once` (#10307) --- packages/core/application/application-common.ts | 1 + packages/core/application/application.android.ts | 16 ++++++++-------- packages/core/jest.setup.ts | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index bd818ff65..9977a8dc3 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -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); diff --git a/packages/core/application/application.android.ts b/packages/core/application/application.android.ts index eb38e0c81..b520b303a 100644 --- a/packages/core/application/application.android.ts +++ b/packages/core/application/application.android.ts @@ -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({ diff --git a/packages/core/jest.setup.ts b/packages/core/jest.setup.ts index 3ee85d45d..eb4312fe8 100644 --- a/packages/core/jest.setup.ts +++ b/packages/core/jest.setup.ts @@ -98,6 +98,7 @@ global.CFRunLoopWakeUp = function (runloop) {}; global.NativeScriptGlobals = { events: { on: (args) => {}, + once: (args) => {}, off: (args) => {}, notify: (args) => {}, hasListeners: (args) => {},