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); on(event: 'activityRequestPermissions', callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
} }
const androidApp = new AndroidApplication(); let androidApp: AndroidApplication;
export { androidApp as android }; export { androidApp as android };
appCommon.setApplication(androidApp);
let mainEntry: NavigationEntry; let mainEntry: NavigationEntry;
let started = false; let started = false;
export function run(entry?: NavigationEntry | string) { export function run(entry?: NavigationEntry | string) {
if (!androidApp) {
androidApp = new AndroidApplication();
appCommon.setApplication(androidApp);
}
if (started) { if (started) {
throw new Error('Application is already started.'); throw new Error('Application is already started.');
} }

View File

@ -349,10 +349,9 @@ export class iOSApplication implements iOSApplicationDefinition {
} }
/* tslint:disable */ /* tslint:disable */
const iosApp = new iOSApplication(); let iosApp: iOSApplication;
/* tslint:enable */ /* tslint:enable */
export { iosApp as ios }; export { iosApp as ios };
setApplication(iosApp);
// attach on global, so it can be overwritten in NativeScript Angular // attach on global, so it can be overwritten in NativeScript Angular
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) { (<any>global).__onLiveSyncCore = function (context?: ModuleContext) {
@ -389,6 +388,11 @@ export function getRootView() {
let started = false; let started = false;
export function run(entry?: string | NavigationEntry) { export function run(entry?: string | NavigationEntry) {
if (!iosApp) {
iosApp = new iOSApplication();
setApplication(iosApp);
}
mainEntry = typeof entry === 'string' ? { moduleName: entry } : entry; mainEntry = typeof entry === 'string' ? { moduleName: entry } : entry;
started = true; started = true;