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,71 +0,0 @@
/**
* @module "ui/core/bindable"
*/ /** */
import { ViewBase } from "../view-base";
import { Observable, WrappedValue, PropertyChangeData, EventData } from "../../../data/observable";
import {
isEnabled as traceEnabled,
write as traceWrite,
error as traceError,
categories as traceCategories,
notifyEvent as traceNotifyEvent,
messageType as traceMessageType,
isCategorySet
} from "../../../trace";
export {
Observable, WrappedValue, PropertyChangeData, EventData,
traceEnabled, traceWrite, traceError, traceCategories, traceNotifyEvent,
traceMessageType, isCategorySet
};
/**
* The options object used in the Bindable.bind method.
*/
export interface BindingOptions {
/**
* The property name of the source object (typically the ViewModel) to bind to.
*/
sourceProperty: string;
/**
* The property name of the target object (that is the Bindable instance) to bind the source property to.
*/
targetProperty: string;
/**
* True to establish a two-way binding, false otherwise. A two-way binding will synchronize both the source and the target property values regardless of which one initiated the change.
*/
twoWay?: boolean;
/**
* An expression used for calculations (convertions) based on the value of the property.
*/
expression?: string;
}
/**
* An interface which defines methods need to create binding value converter.
*/
export interface ValueConverter {
/**
* A method that will be executed when a value (of the binding property) should be converted to the observable model.
* For example: user types in a text field, but our business logic requires to store data in a different manner (e.g. in lower case).
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toModel: (...params: any[]) => any;
/**
* A method that will be executed when a value should be converted to the UI view. For example we have a date object which should be displayed to the end user in a specific date format.
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toView: (...params: any[]) => any;
}
export class Binding {
constructor(target: ViewBase, options: BindingOptions);
public bind(source: Object): void;
public unbind();
public sourceIsBindingContext: boolean;
public updateTwoWay(value: any);
}
export function getEventOrGestureName(name: string): string;
export function isEventOrGesture(name: string, view: ViewBase): boolean;

View File

@@ -1,5 +1,4 @@
// Types
import { BindingOptions } from ".";
import { ViewBase } from "../view-base";
// Requires
@@ -9,13 +8,7 @@ import { addWeakEventListener, removeWeakEventListener } from "../weak-event-lis
import { bindingConstants, parentsRegex } from "../../builder/binding-builder";
import { escapeRegexSymbols } from "../../../utils/utils";
import {
isEnabled as traceEnabled,
write as traceWrite,
error as traceError,
categories as traceCategories,
notifyEvent as traceNotifyEvent,
isCategorySet,
messageType as traceMessageType
Trace
} from "../../../trace";
import * as types from "../../../utils/types";
import * as bindableResources from "./bindable-resources";
@@ -59,6 +52,45 @@ function getProperties(property: string): Array<string> {
return result;
}
/**
* The options object used in the Bindable.bind method.
*/
export interface BindingOptions {
/**
* The property name of the source object (typically the ViewModel) to bind to.
*/
sourceProperty: string;
/**
* The property name of the target object (that is the Bindable instance) to bind the source property to.
*/
targetProperty: string;
/**
* True to establish a two-way binding, false otherwise. A two-way binding will synchronize both the source and the target property values regardless of which one initiated the change.
*/
twoWay?: boolean;
/**
* An expression used for calculations (convertions) based on the value of the property.
*/
expression?: string;
}
/**
* An interface which defines methods need to create binding value converter.
*/
export interface ValueConverter {
/**
* A method that will be executed when a value (of the binding property) should be converted to the observable model.
* For example: user types in a text field, but our business logic requires to store data in a different manner (e.g. in lower case).
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toModel: (...params: any[]) => any;
/**
* A method that will be executed when a value should be converted to the UI view. For example we have a date object which should be displayed to the end user in a specific date format.
* @param params - An array of parameters where first element is the value of the property and next elements are parameters send to converter.
*/
toView: (...params: any[]) => any;
}
export function getEventOrGestureName(name: string): string {
return name.indexOf("on") === 0 ? name.substr(2, name.length - 2) : name;
}
@@ -348,7 +380,7 @@ export class Binding {
let expressionValue = this._getExpressionValue(updateExpression, true, changedModel);
if (expressionValue instanceof Error) {
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
Trace.write((<Error>expressionValue).message, Trace.categories.Binding, Trace.messageType.error);
}
newValue = expressionValue;
@@ -410,7 +442,7 @@ export class Binding {
if (this.options.expression) {
const expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
if (expressionValue instanceof Error) {
traceWrite(expressionValue.message, traceCategories.Binding, traceMessageType.error);
Trace.write(expressionValue.message, Trace.categories.Binding, Trace.messageType.error);
} else {
this.updateTarget(expressionValue);
}
@@ -517,7 +549,7 @@ export class Binding {
changedModel[bc.bindingValueKey] = this.source ? this.source.get() : undefined;
let expressionValue = this._getExpressionValue(this.options.expression, false, changedModel);
if (expressionValue instanceof Error) {
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
Trace.write((<Error>expressionValue).message, Trace.categories.Binding, Trace.messageType.error);
}
else {
return expressionValue;
@@ -534,7 +566,7 @@ export class Binding {
this.sourceOptions.property in sourceOptionsInstance) {
return sourceOptionsInstance[this.sourceOptions.property];
} else {
traceWrite("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", traceCategories.Binding, traceMessageType.error);
Trace.write("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", Trace.categories.Binding, Trace.messageType.error);
}
}
@@ -635,9 +667,9 @@ export class Binding {
optionsInstance[options.property] = value;
}
} catch (ex) {
traceWrite("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
traceCategories.Binding,
traceMessageType.error);
Trace.write("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
Trace.categories.Binding,
Trace.messageType.error);
}
this.updating = false;

View File

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

View File

@@ -1,8 +1,4 @@
/**
* @module "ui/core/control-state-change"
*/ /** */
/**
* An utility class used for supporting styling infrastructure.
* WARNING: This class is intended for IOS only.
*/

View File

@@ -1,23 +1,55 @@
import * as reduceCSSCalc from "reduce-css-calc";
// Definitions.
import * as definitions from "../view-base";
import { ViewBase } from "../view-base";
// Types.
import { WrappedValue, PropertyChangeData } from "../../../data/observable";
import {
write as traceWrite,
categories as traceCategories,
messageType as traceMessageType,
Trace
} from "../../../trace";
import { Style } from "../../styling/style";
import { profile } from "../../../profiling";
/**
* Value specifing that Property should be set to its initial value.
*/
export const unsetValue: any = new Object();
export interface PropertyOptions<T, U> {
readonly name: string;
readonly defaultValue?: U;
readonly affectsLayout?: boolean;
readonly equalityComparer?: (x: U, y: U) => boolean;
readonly valueChanged?: (target: T, oldValue: U, newValue: U) => void;
readonly valueConverter?: (value: string) => U;
}
export interface CoerciblePropertyOptions<T, U> extends PropertyOptions<T, U> {
readonly coerceValue: (t: T, u: U) => U;
}
export interface CssPropertyOptions<T extends Style, U> extends PropertyOptions<T, U> {
readonly cssName: string;
}
export interface ShorthandPropertyOptions<P> {
readonly name: string,
readonly cssName: string;
readonly converter: (value: string | P) => [CssProperty<any, any> | CssAnimationProperty<any, any>, any][],
readonly getter: (this: Style) => string | P
}
export interface CssAnimationPropertyOptions<T, U> {
readonly name: string;
readonly cssName?: string;
readonly defaultValue?: U;
readonly equalityComparer?: (x: U, y: U) => boolean;
readonly valueChanged?: (target: T, oldValue: U, newValue: U) => void;
readonly valueConverter?: (value: string) => U;
}
let cssPropertyNames: string[] = [];
let symbolPropertyMap = {};
let cssSymbolPropertyMap = {};
@@ -132,7 +164,7 @@ function getPropertiesFromMap(map): Property<any, any>[] | CssProperty<any, any>
return props;
}
export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<U>, definitions.Property<T, U> {
export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<U>, Property<T, U> {
private registered: boolean;
public readonly name: string;
@@ -152,7 +184,7 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
public enumerable: boolean = true;
public configurable: boolean = true;
constructor(options: definitions.PropertyOptions<T, U>) {
constructor(options: PropertyOptions<T, U>) {
const propertyName = options.name;
this.name = propertyName;
@@ -302,10 +334,10 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
}
Property.prototype.isStyleProperty = false;
export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> implements definitions.CoercibleProperty<T, U> {
export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> implements CoercibleProperty<T, U> {
public readonly coerce: (target: T) => void;
constructor(options: definitions.CoerciblePropertyOptions<T, U>) {
constructor(options: CoerciblePropertyOptions<T, U>) {
super(options);
const propertyName = options.name;
@@ -415,11 +447,11 @@ export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> imp
}
}
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> implements definitions.InheritedProperty<T, U> {
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> implements InheritedProperty<T, U> {
public readonly sourceKey: symbol;
public readonly setInheritedValue: (value: U) => void;
constructor(options: definitions.PropertyOptions<T, U>) {
constructor(options: PropertyOptions<T, U>) {
super(options);
const name = options.name;
const key = this.key;
@@ -488,7 +520,7 @@ export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> imp
}
}
export class CssProperty<T extends Style, U> implements definitions.CssProperty<T, U> {
export class CssProperty<T extends Style, U> implements CssProperty<T, U> {
private registered: boolean;
public readonly name: string;
@@ -507,7 +539,7 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
public readonly defaultValueKey: symbol;
public readonly defaultValue: U;
constructor(options: definitions.CssPropertyOptions<T, U>) {
constructor(options: CssPropertyOptions<T, U>) {
const propertyName = options.name;
this.name = propertyName;
@@ -545,7 +577,7 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
function setLocalValue(this: T, newValue: U | string): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
Trace.write(`${newValue} not set to view because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
return;
}
@@ -619,7 +651,7 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
function setCssValue(this: T, newValue: U | string): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
Trace.write(`${newValue} not set to view because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
return;
}
@@ -736,7 +768,7 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
}
CssProperty.prototype.isStyleProperty = true;
export class CssAnimationProperty<T extends Style, U> implements definitions.CssAnimationProperty<T, U> {
export class CssAnimationProperty<T extends Style, U> implements CssAnimationProperty<T, U> {
public readonly name: string;
public readonly cssName: string;
public readonly cssLocalName: string;
@@ -759,7 +791,7 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
public _valueConverter?: (value: string) => any;
constructor(options: definitions.CssAnimationPropertyOptions<T, U>) {
constructor(options: CssAnimationPropertyOptions<T, U>) {
const { valueConverter, equalityComparer, valueChanged, defaultValue } = options;
const propertyName = options.name;
this.name = propertyName;
@@ -809,7 +841,7 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
set(this: T, boxedValue: U | string) {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${boxedValue} not set to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
Trace.write(`${boxedValue} not set to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
return;
}
@@ -912,7 +944,7 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
public _initDefaultNativeValue(target: T): void {
const view = target.viewRef.get();
if (!view) {
traceWrite(`_initDefaultNativeValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
Trace.write(`_initDefaultNativeValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
return;
}
@@ -939,10 +971,10 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
}
CssAnimationProperty.prototype.isStyleProperty = true;
export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> implements definitions.InheritedCssProperty<T, U> {
export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> implements InheritedCssProperty<T, U> {
public setInheritedValue: (value: U) => void;
constructor(options: definitions.CssPropertyOptions<T, U>) {
constructor(options: CssPropertyOptions<T, U>) {
super(options);
const propertyName = options.name;
@@ -964,7 +996,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${boxedValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
Trace.write(`${boxedValue} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
return;
}
@@ -1077,7 +1109,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
}
}
export class ShorthandProperty<T extends Style, P> implements definitions.ShorthandProperty<T, P> {
export class ShorthandProperty<T extends Style, P> implements ShorthandProperty<T, P> {
private registered: boolean;
public readonly key: symbol;
@@ -1091,7 +1123,7 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
public readonly sourceKey: symbol;
constructor(options: definitions.ShorthandPropertyOptions<P>) {
constructor(options: ShorthandPropertyOptions<P>) {
this.name = options.name;
const key = Symbol(this.name + ":propertyKey");
@@ -1105,7 +1137,7 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
function setLocalValue(this: T, value: string | P): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`setLocalValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
Trace.write(`setLocalValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
return;
}
@@ -1120,7 +1152,7 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
function setCssValue(this: T, value: string): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`setCssValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
Trace.write(`setCssValue not executed to view because ".viewRef" is cleared`, Trace.categories.Animation, Trace.messageType.warn);
return;
}

View File

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

View File

@@ -1,165 +0,0 @@
/**
* @module "ui/core/properties"
*/ /** */
import { ViewBase } from "../view-base";
import { Style } from "../../styling/style";
export { Style };
/**
* Value specifing that Property should be set to its initial value.
*/
export const unsetValue: any;
export interface PropertyOptions<T, U> {
readonly name: string;
readonly defaultValue?: U;
readonly affectsLayout?: boolean;
readonly equalityComparer?: (x: U, y: U) => boolean;
readonly valueChanged?: (target: T, oldValue: U, newValue: U) => void;
readonly valueConverter?: (value: string) => U;
}
export interface CoerciblePropertyOptions<T, U> extends PropertyOptions<T, U> {
readonly coerceValue: (t: T, u: U) => U;
}
export interface CssPropertyOptions<T extends Style, U> extends PropertyOptions<T, U> {
readonly cssName: string;
}
export interface ShorthandPropertyOptions<P> {
readonly name: string,
readonly cssName: string;
readonly converter: (value: string | P) => [CssProperty<any, any> | CssAnimationProperty<any, any>, any][],
readonly getter: (this: Style) => string | P
}
export interface CssAnimationPropertyOptions<T, U> {
readonly name: string;
readonly cssName?: string;
readonly defaultValue?: U;
readonly equalityComparer?: (x: U, y: U) => boolean;
readonly valueChanged?: (target: T, oldValue: U, newValue: U) => void;
readonly valueConverter?: (value: string) => U;
}
export class Property<T extends ViewBase, U> {
constructor(options: PropertyOptions<T, U>);
public readonly getDefault: symbol;
public readonly setNative: symbol;
public readonly defaultValue: U;
public register(cls: { prototype: T }): void;
public nativeValueChange(owner: T, value: U): void;
public isSet(instance: T): boolean;
}
export interface Property<T extends ViewBase, U> extends TypedPropertyDescriptor<U> {
}
export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> {
constructor(options: CoerciblePropertyOptions<T, U>);
public readonly coerce: (target: T) => void;
}
export interface CoercibleProperty<T extends ViewBase, U> extends TypedPropertyDescriptor<U> {
}
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> {
constructor(options: PropertyOptions<T, U>);
}
export class CssProperty<T extends Style, U> {
constructor(options: CssPropertyOptions<T, U>);
public readonly getDefault: symbol;
public readonly setNative: symbol;
public readonly name: string;
public readonly cssName: string;
public readonly cssLocalName: string;
public readonly defaultValue: U;
public register(cls: { prototype: T }): void;
public isSet(instance: T): boolean;
}
export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U> {
constructor(options: CssPropertyOptions<T, U>);
}
export class ShorthandProperty<T extends Style, P> {
constructor(options: ShorthandPropertyOptions<P>);
public readonly name: string;
public readonly cssName: string;
public register(cls: typeof Style): void;
}
export class CssAnimationProperty<T extends Style, U> {
constructor(options: CssAnimationPropertyOptions<T, U>);
public readonly getDefault: symbol;
public readonly setNative: symbol;
public readonly name: string;
public readonly cssName: string;
public readonly cssLocalName: string;
readonly keyframe: string;
public readonly defaultValue: U;
public register(cls: { prototype: T }): void;
public isSet(instance: T): boolean;
/**
* @private
*/
public _initDefaultNativeValue(target: T): void;
/**
* @private
*/
public _valueConverter?: (value: string) => any;
/**
* @private
*/
public static _getByCssName(name: string): CssAnimationProperty<any, any>;
/**
* @private
*/
public static _getPropertyNames(): string[];
}
export function initNativeView(view: ViewBase): void;
export function resetNativeView(view: ViewBase): void;
export function resetCSSProperties(style: Style): void;
export function propagateInheritableProperties(view: ViewBase, childView: ViewBase): void;
export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void;
export function clearInheritedProperties(view: ViewBase): void;
export function makeValidator<T>(...values: T[]): (value: any) => value is T;
export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T;
export function getSetProperties(view: ViewBase): [string, any][];
export function getComputedCssValues(view: ViewBase): [string, any][];
export function isCssVariable(property: string): boolean;
export function isCssCalcExpression(value: string): boolean;
export function isCssVariableExpression(value: string): boolean;
//@private
/**
* @private get all properties defined on ViewBase
*/
export function _getProperties(): Property<any, any>[];
/**
* @private get all properties defined on Style
*/
export function _getStyleProperties(): CssProperty<any, any>[];
export function _evaluateCssVariableExpression(view: ViewBase, cssName: string, value: string): string;
export function _evaluateCssCalcExpression(value: string): string;
//@endprivate

View File

@@ -1,26 +1,13 @@
/**
* @module "ui/core/view-base"
*/ /** */
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, Style } from "../properties";
import { BindingOptions, Observable } from "../bindable";
import { BindingOptions } from "../bindable";
import { Observable } from "../../../data/observable";
import { SelectorCore } from "../../styling/css-selector";
import { isIOS, isAndroid } from "../../../platform";
import { KeyframeAnimation } from "../../animation/keyframe-animation";
import { Page } from "../../page";
import { layout } from "../../../utils/utils";
import { Color } from "../../../color";
import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "../../layouts/flexbox-layout";
import { Length } from "../../styling/style-properties";
import { DOMNode } from "../../../debugger/dom-node";
export { isIOS, isAndroid, layout, Color };
export * from "../properties";
export * from "../bindable";
/**
* Iterates through all child views (via visual tree) and executes a function.
* @param view - Starting view (parent container).

View File

@@ -1,15 +1,17 @@
// Definitions.
import { ViewBase as ViewBaseDefinition } from ".";
import {
AlignSelf, FlexGrow, FlexShrink, FlexWrapBefore, Order
AlignSelf, FlexGrow, FlexShrink, FlexWrapBefore, Order
} from "../../layouts/flexbox-layout";
import { Page } from "../../page";
// Types.
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, Style, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from "../properties";
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from "../properties";
import { getSystemCssClasses, MODAL_ROOT_VIEW_CSS_CLASS, ROOT_VIEW_CSS_CLASS } from "../../../css/system-classes";
import { Source } from "../../../utils/debug";
import { Binding, BindingOptions, Observable, WrappedValue, PropertyChangeData, traceEnabled, traceWrite, traceCategories } from "../bindable";
import { Binding, BindingOptions } from "../bindable";
import { Trace } from "../../../trace";
import { Observable, PropertyChangeData, WrappedValue } from "../../../data/observable";
import { Style } from "../../styling/style";
import { isAndroid } from "../../../platform";
import { Length, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from "../../styling/style-properties";
@@ -20,6 +22,7 @@ import { profile } from "../../../profiling";
import * as dnm from "../../../debugger/dom-node";
import * as ssm from "../../styling/style-scope";
import { ViewBase as ViewBaseDefinition } from ".";
let domNodeModule: typeof dnm;
@@ -582,8 +585,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
@profile
public _addView(view: ViewBase, atIndex?: number) {
if (traceEnabled()) {
traceWrite(`${this}._addView(${view}, ${atIndex})`, traceCategories.ViewHierarchy);
if (Trace.isEnabled()) {
Trace.write(`${this}._addView(${view}, ${atIndex})`, Trace.categories.ViewHierarchy);
}
if (!view) {
@@ -639,8 +642,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
* Core logic for removing a child view from this instance. Used by the framework to handle lifecycle events more centralized. Do not use outside the UI Stack implementation.
*/
public _removeView(view: ViewBase) {
if (traceEnabled()) {
traceWrite(`${this}._removeView(${view})`, traceCategories.ViewHierarchy);
if (Trace.isEnabled()) {
Trace.write(`${this}._removeView(${view})`, Trace.categories.ViewHierarchy);
}
if (view.parent !== this) {
@@ -881,8 +884,8 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
}
public _goToVisualState(state: string) {
if (traceEnabled()) {
traceWrite(this + " going to state: " + state, traceCategories.Style);
if (Trace.isEnabled()) {
Trace.write(this + " going to state: " + state, Trace.categories.Style);
}
if (state === this._visualState) {

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;
}
}

View File

@@ -1,7 +1,3 @@
/**
* @module "ui/core/weak-event-listener"
*/ /** */
import { Observable, EventData } from "../../../data/observable";
/**