From 88e355d8144cff4d13c59ac83cdbc2c00fd2fe35 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 4 Jan 2022 15:21:27 -0800 Subject: [PATCH] fix: application instance creation occurs only within Application.run --- packages/core/application/index.android.ts | 8 ++++++-- packages/core/application/index.ios.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/application/index.android.ts b/packages/core/application/index.android.ts index b9ea5c926..94a165b25 100644 --- a/packages/core/application/index.android.ts +++ b/packages/core/application/index.android.ts @@ -159,14 +159,18 @@ export interface AndroidApplication { on(event: 'activityRequestPermissions', callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any); } -const androidApp = new AndroidApplication(); +let androidApp: AndroidApplication; export { androidApp as android }; -appCommon.setApplication(androidApp); let mainEntry: NavigationEntry; let started = false; export function run(entry?: NavigationEntry | string) { + if (!androidApp) { + androidApp = new AndroidApplication(); + appCommon.setApplication(androidApp); + } + if (started) { throw new Error('Application is already started.'); } diff --git a/packages/core/application/index.ios.ts b/packages/core/application/index.ios.ts index cf9e84751..2ae32acbb 100644 --- a/packages/core/application/index.ios.ts +++ b/packages/core/application/index.ios.ts @@ -349,10 +349,9 @@ export class iOSApplication implements iOSApplicationDefinition { } /* tslint:disable */ -const iosApp = new iOSApplication(); +let iosApp: iOSApplication; /* tslint:enable */ export { iosApp as ios }; -setApplication(iosApp); // attach on global, so it can be overwritten in NativeScript Angular (global).__onLiveSyncCore = function (context?: ModuleContext) { @@ -389,6 +388,11 @@ export function getRootView() { let started = false; export function run(entry?: string | NavigationEntry) { + if (!iosApp) { + iosApp = new iOSApplication(); + setApplication(iosApp); + } + mainEntry = typeof entry === 'string' ? { moduleName: entry } : entry; started = true;