diff --git a/packages/core/application/application.ios.ts b/packages/core/application/application.ios.ts index 3910ae3a3c..aa7ccbb77d 100644 --- a/packages/core/application/application.ios.ts +++ b/packages/core/application/application.ios.ts @@ -1,5 +1,5 @@ import { profile } from '../profiling'; -import { ContentView } from '../ui/content-view'; +import type { ContentView } from '../ui/content-view'; import type { View } from '../ui/core/view'; import { isEmbedded } from '../ui/embedding'; import { IOSHelper } from '../ui/core/view/view-helper'; @@ -19,7 +19,7 @@ import type { WindowRole } from '../native-window/window-base'; import { NativeWindowEvents } from '../native-window/native-window-interfaces'; import type { NativeWindowEventData, WindowContentRequest, WindowOpenOptions } from '../native-window/native-window-interfaces'; import { CoreTypes } from '../core-types'; -import { getiOSWindow, setApplicationPropertiesCallback, setAppMainEntry, setiOSWindow, setRootView, setToggleApplicationEventListenersCallback } from './helpers-common'; +import { createContentView, getiOSWindow, setApplicationPropertiesCallback, setAppMainEntry, setiOSWindow, setRootView, setToggleApplicationEventListenersCallback } from './helpers-common'; @NativeClass class NotificationObserver extends NSObject { @@ -1223,7 +1223,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication * window's actual root view (see `_contentHosts`). */ private setHostedWindowContent(window: NativeWindow, userView: View): void { - const host = new ContentView(); + const host = createContentView() as ContentView; this._contentHosts.add(host); // Sets the host up as a root view (CSS classes, native controller) and, for the primary @@ -1277,7 +1277,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication this._rootView._onRootViewReset(); } - const rootView = new ContentView(); + const rootView = createContentView() as ContentView; this._contentHosts.add(rootView); const controller = this.getViewController(rootView); diff --git a/packages/core/application/helpers-common.ts b/packages/core/application/helpers-common.ts index 5a46847b7d..b416b6b830 100644 --- a/packages/core/application/helpers-common.ts +++ b/packages/core/application/helpers-common.ts @@ -175,6 +175,18 @@ export function setApplicationPropertiesCallback(callback: () => ApplicationProp _applicationPropertiesCallback = callback; } +// Lets the application create its root host without importing the UI stack, which workers must not load +let _contentViewFactory: () => any /* ContentView */; +export function setContentViewFactory(factory: () => any /* ContentView */) { + _contentViewFactory = factory; +} +export function createContentView(): any /* ContentView */ { + if (!_contentViewFactory) { + throw new Error('ContentView is not registered: import "@nativescript/core/ui/content-view" before creating the root view.'); + } + return _contentViewFactory(); +} + let _a11yUpdatePropertiesCallback: (view: any /* View */) => void; export function setA11yUpdatePropertiesCallback(callback: (view: any /* View */) => void) { _a11yUpdatePropertiesCallback = callback; diff --git a/packages/core/ui/content-view/index.ts b/packages/core/ui/content-view/index.ts index fb1e5c81c3..b949c0b12a 100644 --- a/packages/core/ui/content-view/index.ts +++ b/packages/core/ui/content-view/index.ts @@ -1,5 +1,6 @@ import { View, CustomLayoutView, AddChildFromBuilder } from '../core/view'; import { layout } from '../../utils'; +import { setContentViewFactory } from '../../application/helpers-common'; /** * Represents a View that has a single child - content. @@ -104,3 +105,4 @@ export class ContentView extends CustomLayoutView implements AddChildFromBuilder } ContentView.prototype.recycleNativeView = 'auto'; +setContentViewFactory(() => new ContentView());