chore: remove critical circular dependencies (#8114)

* chore: remove critical circular dependencies

* chore: fix tslint errors

* chore: remove platform specific types from interfaces

* chore: update unit tests polyfills

* fix: incorrect null check

* chore: update api.md file

* test: improve test case

* chore: apply comments

* test: avoid page style leaks in tests
This commit is contained in:
Martin Yankov
2019-11-28 13:36:34 +02:00
committed by Alexander Vakrilov
parent 5b647bd809
commit 0ffc790d82
72 changed files with 1958 additions and 1307 deletions

View File

@ -1,19 +1,22 @@
// Types
import { iOSApplication as iOSApplicationDefinition } from ".";
import {
ApplicationEventData,
CssChangedEventData,
iOSApplication as IOSApplicationDefinition,
LaunchEventData,
LoadAppCSSEventData,
OrientationChangedEventData,
SystemAppearanceChangedEventData
} from ".";
} from "./application-interfaces";
import { View } from "../ui/core/view";
import { NavigationEntry } from "../ui/frame/frame-interfaces";
// Require
import {
displayedEvent, exitEvent, getCssFileName, launchEvent, livesync, lowMemoryEvent, notify, on,
orientationChanged, orientationChangedEvent, resumeEvent, setApplication, suspendEvent,
systemAppearanceChanged, systemAppearanceChangedEvent
} from "./application-common";
// First reexport so that app module is initialized.
export * from "./application-common";
@ -24,9 +27,7 @@ import {
getRootViewCssClasses,
pushToRootViewCssClasses
} from "../css/system-classes";
import { ios as iosView, View } from "../ui/core/view";
import { Frame, NavigationEntry } from "../ui/frame";
import { ios as iosViewHelper } from "../ui/core/view/view-helper";
import { device } from "../platform/platform";
import { profile } from "../profiling";
import { ios } from "../utils/utils";
@ -88,7 +89,9 @@ class CADisplayLinkTarget extends NSObject {
};
}
class IOSApplication implements IOSApplicationDefinition {
/* tslint:disable */
export class iOSApplication implements iOSApplicationDefinition {
/* tslint:enable */
private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor;
private _delegate: typeof UIApplicationDelegate;
private _window: UIWindow;
@ -293,13 +296,8 @@ class IOSApplication implements IOSApplicationDefinition {
this._rootView = rootView;
if (createRootFrame.value) {
// Don't setup as styleScopeHost
rootView._setupUI({});
} else {
// setup view as styleScopeHost
rootView._setupAsRootView({});
}
// setup view as styleScopeHost
rootView._setupAsRootView({});
setViewControllerView(rootView);
@ -312,7 +310,7 @@ class IOSApplication implements IOSApplicationDefinition {
this._window.makeKeyAndVisible();
}
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
rootView.on(iosViewHelper.traitCollectionColorAppearanceChangedEvent, () => {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
@ -331,8 +329,9 @@ class IOSApplication implements IOSApplicationDefinition {
}
}
const iosApp = new IOSApplication();
/* tslint:disable */
const iosApp = new iOSApplication();
/* tslint:enable */
export { iosApp as ios };
setApplication(iosApp);
@ -350,12 +349,7 @@ function createRootView(v?: View) {
if (!mainEntry) {
throw new Error("Main entry is missing. App cannot be started. Verify app bootstrap.");
} else {
if (createRootFrame.value) {
const frame = rootView = new Frame();
frame.navigate(mainEntry);
} else {
rootView = Builder.createViewFromEntry(mainEntry);
}
rootView = Builder.createViewFromEntry(mainEntry);
}
}
@ -372,10 +366,8 @@ export function getRootView() {
return iosApp.rootView;
}
// NOTE: for backwards compatibility. Remove for 4.0.0.
const createRootFrame = { value: true };
let started: boolean = false;
export function _start(entry?: string | NavigationEntry) {
export function run(entry?: string | NavigationEntry) {
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true;
@ -404,7 +396,7 @@ export function _start(entry?: string | NavigationEntry) {
// Mind root view CSS classes in future work
// on embedding NativeScript applications
setRootViewSystemAppearanceCssClass(rootView);
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
rootView.on(iosViewHelper.traitCollectionColorAppearanceChangedEvent, () => {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
@ -426,11 +418,6 @@ export function _start(entry?: string | NavigationEntry) {
}
}
export function run(entry?: string | NavigationEntry) {
createRootFrame.value = false;
_start(entry);
}
export function addCss(cssText: string, attributeScoped?: boolean): void {
notify(<CssChangedEventData>{ eventName: "cssChanged", object: <any>iosApp, cssText: cssText });
if (!attributeScoped) {
@ -442,7 +429,6 @@ export function addCss(cssText: string, attributeScoped?: boolean): void {
}
export function _resetRootView(entry?: NavigationEntry | string) {
createRootFrame.value = false;
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
iosApp.setWindowContent();
}
@ -467,7 +453,7 @@ function getViewController(rootView: View): UIViewController {
if (!(viewController instanceof UIViewController)) {
// We set UILayoutViewController dynamically to the root view if it doesn't have a view controller
// At the moment the root view doesn't have its native view created. We set it in the setViewControllerView func
viewController = iosView.UILayoutViewController.initWithOwner(new WeakRef(rootView)) as UIViewController;
viewController = iosViewHelper.UILayoutViewController.initWithOwner(new WeakRef(rootView)) as UIViewController;
rootView.viewController = viewController;
}
@ -482,7 +468,7 @@ function setViewControllerView(view: View): void {
throw new Error("Root should be either UIViewController or UIView");
}
if (viewController instanceof iosView.UILayoutViewController) {
if (viewController instanceof iosViewHelper.UILayoutViewController) {
viewController.view.addSubview(nativeView);
}
}