fix: application instance creation occurs only within Application.run

This commit is contained in:
Nathan Walker
2022-01-04 15:21:27 -08:00
parent 25679a6982
commit a518249958
2 changed files with 12 additions and 4 deletions

View File

@ -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.');
}

View File

@ -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
(<any>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;