mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Merge remote-tracking branch 'origin/master' into merge-release-in-master
This commit is contained in:
@ -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";
|
||||
|
||||
@ -21,12 +24,11 @@ export * from "./application-common";
|
||||
import { Builder } from "../ui/builder";
|
||||
import {
|
||||
CLASS_PREFIX,
|
||||
getRootViewCssClasses,
|
||||
pushToRootViewCssClasses
|
||||
getSystemCssClasses,
|
||||
pushToSystemCssClasses,
|
||||
ROOT_VIEW_CSS_CLASS
|
||||
} 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 +90,9 @@ class CADisplayLinkTarget extends NSObject {
|
||||
};
|
||||
}
|
||||
|
||||
class IOSApplication implements IOSApplicationDefinition {
|
||||
/* tslint:disable */
|
||||
export class iOSApplication implements iOSApplicationDefinition {
|
||||
/* tslint:enable */
|
||||
private _backgroundColor = (majorVersion <= 12 || !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
|
||||
private _delegate: typeof UIApplicationDelegate;
|
||||
private _window: UIWindow;
|
||||
@ -292,26 +296,21 @@ 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);
|
||||
|
||||
const haveController = this._window.rootViewController !== null;
|
||||
this._window.rootViewController = controller;
|
||||
|
||||
setRootViewSystemAppearanceCssClass(rootView);
|
||||
setRootViewsSystemAppearanceCssClass(rootView);
|
||||
|
||||
if (!haveController) {
|
||||
this._window.makeKeyAndVisible();
|
||||
}
|
||||
|
||||
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
|
||||
rootView.on(iosViewHelper.traitCollectionColorAppearanceChangedEvent, () => {
|
||||
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
|
||||
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
|
||||
|
||||
@ -330,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);
|
||||
|
||||
@ -349,16 +349,11 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
setRootViewCssClasses(rootView);
|
||||
setRootViewsCssClasses(rootView);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
@ -371,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;
|
||||
|
||||
@ -402,8 +395,8 @@ export function _start(entry?: string | NavigationEntry) {
|
||||
|
||||
// Mind root view CSS classes in future work
|
||||
// on embedding NativeScript applications
|
||||
setRootViewSystemAppearanceCssClass(rootView);
|
||||
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
|
||||
setRootViewsSystemAppearanceCssClass(rootView);
|
||||
rootView.on(iosViewHelper.traitCollectionColorAppearanceChangedEvent, () => {
|
||||
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
|
||||
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
|
||||
|
||||
@ -425,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) {
|
||||
@ -441,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();
|
||||
}
|
||||
@ -466,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;
|
||||
}
|
||||
|
||||
@ -481,25 +468,27 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
function setRootViewCssClasses(rootView: View): void {
|
||||
function setRootViewsCssClasses(rootView: View): void {
|
||||
const deviceType = device.deviceType.toLowerCase();
|
||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${IOS_PLATFORM}`);
|
||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${deviceType}`);
|
||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${iosApp.orientation}`);
|
||||
|
||||
const rootViewCssClasses = getRootViewCssClasses();
|
||||
pushToSystemCssClasses(`${CLASS_PREFIX}${IOS_PLATFORM}`);
|
||||
pushToSystemCssClasses(`${CLASS_PREFIX}${deviceType}`);
|
||||
pushToSystemCssClasses(`${CLASS_PREFIX}${iosApp.orientation}`);
|
||||
|
||||
rootView.cssClasses.add(ROOT_VIEW_CSS_CLASS);
|
||||
const rootViewCssClasses = getSystemCssClasses();
|
||||
rootViewCssClasses.forEach(c => rootView.cssClasses.add(c));
|
||||
}
|
||||
|
||||
function setRootViewSystemAppearanceCssClass(rootView: View): void {
|
||||
function setRootViewsSystemAppearanceCssClass(rootView: View): void {
|
||||
if (majorVersion >= 13) {
|
||||
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
|
||||
pushToRootViewCssClasses(systemAppearanceCssClass);
|
||||
pushToSystemCssClasses(systemAppearanceCssClass);
|
||||
rootView.cssClasses.add(systemAppearanceCssClass);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user