chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-04 01:12:55 -07:00
parent 9341cd9554
commit 1525c89733
274 changed files with 1755 additions and 2733 deletions

View File

@@ -1,13 +1,19 @@
// Definitions.
import {
View as ViewDefinition, Point, Size, Color, dip,
View as ViewDefinition, Point, Size, dip,
ShownModallyData
} from ".";
import {
booleanConverter, EventData, getEventOrGestureName, InheritedProperty, layout,
Property, ShowModalOptions, traceCategories, traceEnabled, traceWrite, ViewBase
booleanConverter,
ShowModalOptions, ViewBase
} from "../view-base";
import { getEventOrGestureName } from "../bindable";
import { layout } from "../../../utils/utils";
import { Color } from "../../../color";
import { Property, InheritedProperty } from "../properties";
import { EventData } from "../../../data/observable";
import { Trace } from "../../../trace";
import { ViewHelper } from "./view-helper";
import { HorizontalAlignment, VerticalAlignment, Visibility, Length, PercentLength } from "../../styling/style-properties";
@@ -168,8 +174,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
}
public _onLivesync(context?: ModuleContext): boolean {
if (traceEnabled()) {
traceWrite(`${this}._onLivesync(${JSON.stringify(context)})`, traceCategories.Livesync);
if (Trace.isEnabled()) {
Trace.write(`${this}._onLivesync(${JSON.stringify(context)})`, Trace.categories.Livesync);
}
if (this._closeAllModalViewsInternal()) {
@@ -193,14 +199,14 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
}
public _handleLivesync(context?: ModuleContext): boolean {
if (traceEnabled()) {
traceWrite(`${this}._handleLivesync(${JSON.stringify(context)})`, traceCategories.Livesync);
if (Trace.isEnabled()) {
Trace.write(`${this}._handleLivesync(${JSON.stringify(context)})`, Trace.categories.Livesync);
}
// Handle local CSS
if (viewMatchesModuleContext(this, context, ["style"])) {
if (traceEnabled()) {
traceWrite(`Change Handled: Changing CSS for ${this}`, traceCategories.Livesync);
if (Trace.isEnabled()) {
Trace.write(`Change Handled: Changing CSS for ${this}`, Trace.categories.Livesync);
}
// Always load styles with ".css" extension. Even when changes are in ".scss" ot ".less" files
@@ -216,8 +222,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
this.page &&
this.page.frame) {
if (traceEnabled()) {
traceWrite(`Change Handled: Changing ${context.type} for ${this} inside ${this.page}`, traceCategories.Livesync);
if (Trace.isEnabled()) {
Trace.write(`Change Handled: Changing ${context.type} for ${this} inside ${this.page}`, Trace.categories.Livesync);
}
return this.page.frame._handleLivesync({ type: context.type, path: this.page._moduleName });
@@ -818,8 +824,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
public setMeasuredDimension(measuredWidth: number, measuredHeight: number): void {
this._measuredWidth = measuredWidth;
this._measuredHeight = measuredHeight;
if (traceEnabled()) {
traceWrite(this + " :setMeasuredDimension: " + measuredWidth + ", " + measuredHeight, traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(this + " :setMeasuredDimension: " + measuredWidth + ", " + measuredHeight, Trace.categories.Layout);
}
}

View File

@@ -33,7 +33,7 @@ export class ViewHelper {
public static combineMeasuredStates(curState: number, newState): number;
}
export namespace ios {
export namespace IOSHelper {
/**
* String value used when hooking to traitCollectionColorAppearanceChangedEvent event.
*/

View File

@@ -8,17 +8,14 @@ import {
layout
} from "../../../../utils/utils";
import {
isEnabled as traceEnabled,
messageType as traceMessageType,
categories as traceCategories,
write as traceWrite
Trace
} from "../../../../trace";
export * from "./view-helper-common";
const majorVersion = iosUtils.MajorVersion;
export namespace ios {
export namespace IOSHelper {
export const traitCollectionColorAppearanceChangedEvent = "traitCollectionColorAppearanceChanged";
export function getParentWithViewController(view: View): View {
@@ -65,19 +62,19 @@ export namespace ios {
export function layoutView(controller: UIViewController, owner: View): void {
let layoutGuide = controller.view.safeAreaLayoutGuide;
if (!layoutGuide) {
traceWrite(`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`,
traceCategories.Layout, traceMessageType.error);
Trace.write(`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`,
Trace.categories.Layout, Trace.messageType.error);
layoutGuide = initLayoutGuide(controller);
}
const safeArea = layoutGuide.layoutFrame;
let position = ios.getPositionFromFrame(safeArea);
let position = IOSHelper.getPositionFromFrame(safeArea);
const safeAreaSize = safeArea.size;
const hasChildViewControllers = controller.childViewControllers.count > 0;
if (hasChildViewControllers) {
const fullscreen = controller.view.frame;
position = ios.getPositionFromFrame(fullscreen);
position = IOSHelper.getPositionFromFrame(fullscreen);
}
const safeAreaWidth = layout.round(layout.toDevicePixels(safeAreaSize.width));
@@ -117,11 +114,11 @@ export namespace ios {
export function shrinkToSafeArea(view: View, frame: CGRect): CGRect {
const insets = view.getSafeAreaInsets();
if (insets.left || insets.top) {
const position = ios.getPositionFromFrame(frame);
const adjustedFrame = ios.getFrameFromPosition(position, insets);
const position = IOSHelper.getPositionFromFrame(frame);
const adjustedFrame = IOSHelper.getFrameFromPosition(position, insets);
if (traceEnabled()) {
traceWrite(this + " :shrinkToSafeArea: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(this + " :shrinkToSafeArea: " + JSON.stringify(IOSHelper.getPositionFromFrame(adjustedFrame)), Trace.categories.Layout);
}
return adjustedFrame;
@@ -136,10 +133,10 @@ export namespace ios {
const fullscreen = availableSpace.fullscreen;
const inWindow = availableSpace.inWindow;
const position = ios.getPositionFromFrame(frame);
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
const fullscreenPosition = ios.getPositionFromFrame(fullscreen);
const inWindowPosition = ios.getPositionFromFrame(inWindow);
const position = IOSHelper.getPositionFromFrame(frame);
const safeAreaPosition = IOSHelper.getPositionFromFrame(safeArea);
const fullscreenPosition = IOSHelper.getPositionFromFrame(fullscreen);
const inWindowPosition = IOSHelper.getPositionFromFrame(inWindow);
const adjustedPosition = position;
@@ -161,8 +158,8 @@ export namespace ios {
const adjustedFrame = CGRectMake(layout.toDeviceIndependentPixels(adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.top), layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top));
if (traceEnabled()) {
traceWrite(view + " :expandBeyondSafeArea: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(view + " :expandBeyondSafeArea: " + JSON.stringify(IOSHelper.getPositionFromFrame(adjustedFrame)), Trace.categories.Layout);
}
return adjustedFrame;

View File

@@ -1,5 +0,0 @@
{
"name": "view-helper",
"main": "view-helper",
"types": "view-helper.d.ts"
}

View File

@@ -8,9 +8,7 @@ import {
// Requires
import { layout } from "../../../../utils/utils";
import {
isEnabled as traceEnabled,
categories as traceCategories,
write as traceWrite
Trace
} from "../../../../trace";
export class ViewHelper {
@@ -39,8 +37,8 @@ export class ViewHelper {
const childWidthMeasureSpec = ViewHelper.getMeasureSpec(widthMeasureSpec, horizontalMargins, child.effectiveWidth, style.horizontalAlignment === "stretch");
const childHeightMeasureSpec = ViewHelper.getMeasureSpec(heightMeasureSpec, verticalMargins, child.effectiveHeight, style.verticalAlignment === "stretch");
if (traceEnabled()) {
traceWrite(`${child.parent} :measureChild: ${child} ${layout.measureSpecToString(childWidthMeasureSpec)}, ${layout.measureSpecToString(childHeightMeasureSpec)}}`, traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(`${child.parent} :measureChild: ${child} ${layout.measureSpecToString(childWidthMeasureSpec)}, ${layout.measureSpecToString(childHeightMeasureSpec)}}`, Trace.categories.Layout);
}
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
@@ -131,8 +129,8 @@ export class ViewHelper {
childLeft = Math.round(childLeft);
childTop = Math.round(childTop);
if (traceEnabled()) {
traceWrite(child.parent + " :layoutChild: " + child + " " + childLeft + ", " + childTop + ", " + childRight + ", " + childBottom, traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(child.parent + " :layoutChild: " + child + " " + childLeft + ", " + childTop + ", " + childRight + ", " + childBottom, Trace.categories.Layout);
}
child.layout(childLeft, childTop, childRight, childBottom, setFrame);

View File

@@ -3,11 +3,13 @@ import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
import { GestureTypes, GestureEventData } from "../../gestures";
// Types.
import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
traceEnabled, traceWrite, traceCategories, traceNotifyEvent,
ViewCommon, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
Color, EventData, ShowModalOptions
EventData, ShowModalOptions
} from "./view-common";
// import { layout} from "../../layouts"
import { Trace } from "../../../trace";
import { Color } from "../../../color";
import {
perspectiveProperty, Length, PercentLength, Visibility, HorizontalAlignment, VerticalAlignment,
@@ -1035,8 +1037,8 @@ export class CustomLayoutView extends ContainerView implements CustomLayoutViewD
super._addViewToNativeVisualTree(child);
if (this.nativeViewProtected && child.nativeViewProtected) {
if (traceEnabled()) {
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
if (Trace.isEnabled()) {
Trace.write(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, Trace.categories.VisualTreeEvents);
}
this.nativeViewProtected.addView(child.nativeViewProtected, atIndex);
if (child instanceof View) {
@@ -1068,9 +1070,9 @@ export class CustomLayoutView extends ContainerView implements CustomLayoutViewD
const childView = child.nativeViewProtected;
if (nativeView && childView) {
nativeView.removeView(childView);
if (traceEnabled()) {
traceWrite(`${nativeView}.removeView(${childView})`, traceCategories.VisualTreeEvents);
traceNotifyEvent(child, "childInLayoutRemovedFromNativeVisualTree");
if (Trace.isEnabled()) {
Trace.write(`${nativeView}.removeView(${childView})`, Trace.categories.VisualTreeEvents);
Trace.notifyEvent(child, "childInLayoutRemovedFromNativeVisualTree");
}
}
}

View File

@@ -1,19 +1,12 @@
/**
* @module "ui/core/view"
*/ /** */
/// <reference path="../../../tns-core-modules.d.ts" />
import { ViewBase, Property, InheritedProperty, EventData, Color } from "../view-base";
import { ViewBase } from "../view-base";
import { Property, InheritedProperty } from '../properties';
import { EventData } from '../../../data/observable';
import { Color } from '../../../color';
import { Animation, AnimationDefinition, AnimationPromise } from "../../animation";
import { HorizontalAlignment, VerticalAlignment, Visibility, Length, PercentLength } from "../../styling/style-properties";
import { GestureTypes, GestureEventData, GesturesObserver } from "../../gestures";
import { LinearGradient } from "../../styling/gradient";
export * from "../view-base";
export * from "../../styling/style-properties";
export { LinearGradient };
export function PseudoClassHandler(...pseudoClasses: string[]): MethodDecorator;
/**

View File

@@ -3,10 +3,12 @@ import { Point, View as ViewDefinition, dip } from ".";
// Requires
import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
traceEnabled, traceWrite, traceCategories, traceError, traceMessageType, ShowModalOptions
ViewCommon, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty
} from "./view-common";
import { ios } from "./view-helper";
import { ShowModalOptions } from "../view-base";
import { Trace } from "../../../trace";
import { layout } from "../../../utils/utils";
import { IOSHelper } from "./view-helper";
import { ios as iosBackground, Background } from "../../styling/background";
import { ios as iosUtils } from "../../../utils/utils";
import { ios as iosNativeHelper } from "../../../utils/native-helper";
@@ -21,7 +23,7 @@ import {
import { profile } from "../../../profiling";
export * from "./view-common";
export { ios };
export { IOSHelper };
const PFLAG_FORCE_LAYOUT = 1;
const PFLAG_MEASURED_DIMENSION_SET = 1 << 1;
@@ -32,8 +34,8 @@ const majorVersion = iosUtils.MajorVersion;
export class View extends ViewCommon implements ViewDefinition {
nativeViewProtected: UIView;
viewController: UIViewController;
private _popoverPresentationDelegate: ios.UIPopoverPresentationControllerDelegateImp;
private _adaptivePresentationDelegate: ios.UIAdaptivePresentationControllerDelegateImp;
private _popoverPresentationDelegate: IOSHelper.UIPopoverPresentationControllerDelegateImp;
private _adaptivePresentationDelegate: IOSHelper.UIAdaptivePresentationControllerDelegateImp;
private _isLaidOut = false;
private _hasTransfrom = false;
@@ -102,7 +104,7 @@ export class View extends ViewCommon implements ViewDefinition {
// on iOS 11+ it is possible to have a changed layout frame due to safe area insets
// get the frame and adjust the position, so that onLayout works correctly
const frame = this.nativeViewProtected.frame;
position = ios.getPositionFromFrame(frame);
position = IOSHelper.getPositionFromFrame(frame);
}
this.onLayout(position.left, position.top, position.right, position.bottom);
@@ -161,8 +163,8 @@ export class View extends ViewCommon implements ViewDefinition {
let oldFrame = this._cachedFrame || nativeView.frame;
if (!CGRectEqualToRect(oldFrame, frame)) {
if (traceEnabled()) {
traceWrite(this + " :_setNativeViewFrame: " + JSON.stringify(ios.getPositionFromFrame(frame)), traceCategories.Layout);
if (Trace.isEnabled()) {
Trace.write(this + " :_setNativeViewFrame: " + JSON.stringify(IOSHelper.getPositionFromFrame(frame)), Trace.categories.Layout);
}
this._cachedFrame = frame;
let adjustedFrame = null;
@@ -215,7 +217,7 @@ export class View extends ViewCommon implements ViewDefinition {
}
const nativeView = this.nativeViewProtected;
const frame = ios.getFrameFromPosition({ left, top, right, bottom });
const frame = IOSHelper.getFrameFromPosition({ left, top, right, bottom });
this._setNativeViewFrame(nativeView, frame);
}
@@ -250,7 +252,7 @@ export class View extends ViewCommon implements ViewDefinition {
public focus(): boolean {
if (this.ios) {
return this.ios.becomeFirstResponder();
return this.IOSHelper.becomeFirstResponder();
}
return false;
@@ -262,9 +264,9 @@ export class View extends ViewCommon implements ViewDefinition {
}
if (!this.iosOverflowSafeArea || !this.iosOverflowSafeAreaEnabled) {
return ios.shrinkToSafeArea(this, frame);
return IOSHelper.shrinkToSafeArea(this, frame);
} else if (this.nativeViewProtected && this.nativeViewProtected.window) {
return ios.expandBeyondSafeArea(this, frame);
return IOSHelper.expandBeyondSafeArea(this, frame);
}
return null;
@@ -400,25 +402,25 @@ export class View extends ViewCommon implements ViewDefinition {
}
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
const parentWithController = ios.getParentWithViewController(parent);
const parentWithController = IOSHelper.getParentWithViewController(parent);
if (!parentWithController) {
traceWrite(`Could not find parent with viewController for ${parent} while showing modal view.`,
traceCategories.ViewHierarchy, traceMessageType.error);
Trace.write(`Could not find parent with viewController for ${parent} while showing modal view.`,
Trace.categories.ViewHierarchy, Trace.messageType.error);
return;
}
const parentController = parentWithController.viewController;
if (parentController.presentedViewController) {
traceWrite("Parent is already presenting view controller. Close the current modal page before showing another one!",
traceCategories.ViewHierarchy, traceMessageType.error);
Trace.write("Parent is already presenting view controller. Close the current modal page before showing another one!",
Trace.categories.ViewHierarchy, Trace.messageType.error);
return;
}
if (!parentController.view || !parentController.view.window) {
traceWrite("Parent page is not part of the window hierarchy.",
traceCategories.ViewHierarchy, traceMessageType.error);
Trace.write("Parent page is not part of the window hierarchy.",
Trace.categories.ViewHierarchy, Trace.messageType.error);
return;
}
@@ -429,7 +431,7 @@ export class View extends ViewCommon implements ViewDefinition {
let controller = this.viewController;
if (!controller) {
const nativeView = this.ios || this.nativeViewProtected;
controller = <UIViewController>ios.UILayoutViewController.initWithOwner(new WeakRef(this));
controller = <UIViewController>IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(this));
if (nativeView instanceof UIView) {
controller.view.addSubview(nativeView);
@@ -444,13 +446,13 @@ export class View extends ViewCommon implements ViewDefinition {
controller.modalPresentationStyle = UIModalPresentationStyle.FormSheet;
//check whether both height and width is provided and are positive numbers
// set it has prefered content size to the controller presenting the dialog
if (options.ios && options.ios.width > 0 && options.ios.height > 0) {
controller.preferredContentSize = CGSizeMake(options.ios.width, options.ios.height);
if (options.ios && options.IOSHelper.width > 0 && options.IOSHelper.height > 0) {
controller.preferredContentSize = CGSizeMake(options.IOSHelper.width, options.IOSHelper.height);
}
}
if (options.ios && options.ios.presentationStyle) {
const presentationStyle = options.ios.presentationStyle;
if (options.ios && options.IOSHelper.presentationStyle) {
const presentationStyle = options.IOSHelper.presentationStyle;
controller.modalPresentationStyle = presentationStyle;
if (presentationStyle === UIModalPresentationStyle.Popover) {
@@ -490,7 +492,7 @@ export class View extends ViewCommon implements ViewDefinition {
protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) {
if (!parent || !parent.viewController) {
traceError("Trying to hide modal view but no parent with viewController specified.");
Trace.error("Trying to hide modal view but no parent with viewController specified.");
return;
}
@@ -704,7 +706,7 @@ export class View extends ViewCommon implements ViewDefinition {
private _setupPopoverControllerDelegate(controller: UIViewController, parent: View) {
const popoverPresentationController = controller.popoverPresentationController;
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
this._popoverPresentationDelegate = IOSHelper.UIPopoverPresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
popoverPresentationController.delegate = <UIPopoverPresentationControllerDelegate>this._popoverPresentationDelegate;
const view = parent.nativeViewProtected;
// Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
@@ -714,7 +716,7 @@ export class View extends ViewCommon implements ViewDefinition {
}
private _setupAdaptiveControllerDelegate(controller: UIViewController) {
this._adaptivePresentationDelegate = ios.UIAdaptivePresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
this._adaptivePresentationDelegate = IOSHelper.UIAdaptivePresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
controller.presentationController.delegate = <UIAdaptivePresentationControllerDelegate>this._adaptivePresentationDelegate;
}
}