got to layouts

This commit is contained in:
Hristo Hristov
2016-12-09 17:57:17 +02:00
parent 07e2102c5d
commit 19ee47ba24
76 changed files with 941 additions and 1002 deletions

View File

@@ -3,7 +3,6 @@ import { Observable, PropertyChangeData } from "data/observable";
import { unsetValue, DependencyObservable, Property, PropertyMetadata, PropertyMetadataSettings, PropertyChangeData as DependencyPropertyChangeData } from "ui/core/dependency-observable";
import { addWeakEventListener, removeWeakEventListener } from "ui/core/weak-event-listener";
import types = require("utils/types");
import trace = require("trace");
import bindingBuilder = require("../builder/binding-builder");
import { ViewBase, isEventOrGesture } from "ui/core/view-base";
import * as application from "application";
@@ -11,6 +10,8 @@ import * as polymerExpressions from "js-libs/polymer-expressions";
import * as specialProperties from "ui/builder/special-properties";
import * as utils from "utils/utils";
import { enabled as traceEnabled, write as traceWrite, categories as traceCategories, notifyEvent as traceNotifyEvent, messageType as traceMessageType } from "trace";
let bindingContextProperty = new Property(
"bindingContext",
"Bindable",
@@ -86,8 +87,8 @@ export class Bindable extends DependencyObservable implements definition.Bindabl
}
public _onPropertyChanged(property: Property, oldValue: any, newValue: any) {
if (trace.enabled) {
trace.write(`${this}._onPropertyChanged(${property.name}, ${oldValue}, ${newValue})`, trace.categories.Binding);
if (traceEnabled) {
traceWrite(`${this}._onPropertyChanged(${property.name}, ${oldValue}, ${newValue})`, traceCategories.Binding);
}
super._onPropertyChanged(property, oldValue, newValue);
// if (this instanceof viewModule.View) {
@@ -99,14 +100,14 @@ export class Bindable extends DependencyObservable implements definition.Bindabl
let binding = this.bindings.get(property.name);
if (binding && !binding.updating) {
if (binding.options.twoWay) {
if (trace.enabled) {
trace.write(`${this}._updateTwoWayBinding(${property.name}, ${newValue});` + property.name, trace.categories.Binding);
if (traceEnabled) {
traceWrite(`${this}._updateTwoWayBinding(${property.name}, ${newValue});` + property.name, traceCategories.Binding);
}
this._updateTwoWayBinding(property.name, newValue);
}
else {
if (trace.enabled) {
trace.write(`${this}.unbind(${property.name});`, trace.categories.Binding);
if (traceEnabled) {
traceWrite(`${this}.unbind(${property.name});`, traceCategories.Binding);
}
this.unbind(property.name);
}
@@ -125,8 +126,8 @@ export class Bindable extends DependencyObservable implements definition.Bindabl
this.bindings.forEach((binding, index, bindings) => {
if (!binding.updating && binding.sourceIsBindingContext && binding.options.targetProperty !== "bindingContext") {
if (trace.enabled) {
trace.write(`Binding ${binding.target.get()}.${binding.options.targetProperty} to new context ${bindingContextSource}`, trace.categories.Binding);
if (traceEnabled) {
traceWrite(`Binding ${binding.target.get()}.${binding.options.targetProperty} to new context ${bindingContextSource}`, traceCategories.Binding);
}
if (!types.isNullOrUndefined(bindingContextSource)) {
binding.bind(bindingContextSource);
@@ -362,7 +363,7 @@ export class Binding {
let expressionValue = this._getExpressionValue(updateExpression, true, changedModel);
if (expressionValue instanceof Error) {
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
}
newValue = expressionValue;
@@ -421,7 +422,7 @@ export class Binding {
if (this.options.expression) {
let expressionValue = this._getExpressionValue(this.options.expression, false, undefined);
if (expressionValue instanceof Error) {
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
} else {
this.updateTarget(expressionValue);
}
@@ -507,7 +508,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) {
trace.write((<Error>expressionValue).message, trace.categories.Binding, trace.messageType.error);
traceWrite((<Error>expressionValue).message, traceCategories.Binding, traceMessageType.error);
}
else {
return expressionValue;
@@ -524,7 +525,7 @@ export class Binding {
this.sourceOptions.property in sourceOptionsInstance) {
return sourceOptionsInstance[this.sourceOptions.property];
} else {
trace.write("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", trace.categories.Binding, trace.messageType.error);
traceWrite("Property: '" + this.sourceOptions.property + "' is invalid or does not exist. SourceProperty: '" + this.options.sourceProperty + "'", traceCategories.Binding, traceMessageType.error);
}
}
@@ -632,9 +633,9 @@ export class Binding {
}
}
catch (ex) {
trace.write("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
trace.categories.Binding,
trace.messageType.error);
traceWrite("Binding error while setting property " + options.property + " of " + optionsInstance + ": " + ex,
traceCategories.Binding,
traceMessageType.error);
}
this.updating = false;

View File

@@ -7,7 +7,7 @@ declare module "ui/core/dependency-observable" {
/**
* Value specifing that Property value should be reset. Used when bindingContext on bound property is creared/null.
*/
export let unsetValue: Object;
export const unsetValue: Object;
/**
* Interface used by Propery 'defaultValueGetter' function to specify if the default value returned by the native instance can be cached or not.
* One example is - android.widget.Button background. It is state drawable so it cannot be reused/cached.

View File

@@ -9,7 +9,7 @@ import { getClassInfo, isString } from "utils/types";
// use private variables in the scope of the module rather than static members of the class since a member is still accessible through JavaScript and may be changed.
var propertyFromKey = {};
var propertyIdCounter = 0;
export let unsetValue = new Object();
export const unsetValue = new Object();
function generatePropertyKey(name: string, ownerType: string, validate?: boolean) {
if (validate) {

View File

@@ -327,6 +327,7 @@ export class CssProperty<T extends Style, U> {
public key: symbol;
public native: symbol;
public sourceKey: symbol;
public defaultValueKey: symbol;
constructor(options: CssPropertyOptions<T, U>) {
let name = options.name;
@@ -344,6 +345,8 @@ export class CssProperty<T extends Style, U> {
let native = Symbol(name + ":nativeKey");
this.native = native;
let defaultValueKey = Symbol(name + ":nativeDefaultValue");
this.defaultValueKey = defaultValueKey;
let eventName = name + "Change";
let defaultValue: U = options.defaultValue;
let affectsLayout: boolean = options.affectsLayout;
@@ -351,10 +354,6 @@ export class CssProperty<T extends Style, U> {
let valueChanged = options.valueChanged;
let valueConverter = options.valueConverter;
let dependentProperty = options.dependentProperty;
let dependentPropertyKey = dependentProperty ? dependentProperty.key : undefined;
let dependentPropertyNativeKey = dependentProperty ? dependentProperty.native : undefined;
function setLocalValue(this: T, value: U): void {
let reset = value === unsetValue;
if (reset) {
@@ -379,12 +378,12 @@ export class CssProperty<T extends Style, U> {
}
let view = this.view;
if (!(defaultValueKey in this)) {
this[defaultValueKey] = view[native];
}
if (view.nativeView) {
view[native] = value;
if (dependentPropertyNativeKey) {
// Call the native setter for dependent property.
view[dependentPropertyNativeKey] = this[dependentPropertyKey];
}
}
if (valueChanged) {
@@ -438,10 +437,6 @@ export class CssProperty<T extends Style, U> {
let view = this.view;
if (view.nativeView) {
view[native] = value;
if (dependentPropertyNativeKey) {
// Call the native setter for dependent property.
view[dependentPropertyNativeKey] = this[dependentPropertyKey];
}
}
if (valueChanged) {
@@ -799,6 +794,26 @@ export function clearInheritedProperties(view: ViewBase): void {
}
}
export function resetStyleProperties(style: Style): void {
let symbols = (<any>Object).getOwnPropertySymbols(style);
let view = style.view;
for (let symbol of symbols) {
let property: CssProperty<any, any> = symbolPropertyMap[symbol];
if (!property) {
continue;
}
let native = property.native;
if (view[native]) {
view[native] = style[property.defaultValueKey];
delete style[property.defaultValueKey];
}
// This will not call propertyChange!!!
delete style[property.key];
}
}
export function propagateInheritedProperties(view: ViewBase): void {
let inheritablePropertyValues = inheritablePropertyValuesOn(view);
let inheritableCssPropertyValues = inheritableCssPropertyValuesOn(view.style);

View File

@@ -2,14 +2,17 @@ import { ViewBase as ViewBaseDefinition } from "ui/core/view-base";
import { Observable, EventData } from "data/observable";
import { Property, InheritedProperty, CssProperty, Style, clearInheritedProperties, propagateInheritedProperties } from "./properties";
import { Binding, BindingOptions, Bindable } from "ui/core/bindable";
import { isIOS } from "platform";
import { isIOS, isAndroid } from "platform";
import { fromString as gestureFromString } from "ui/gestures";
import { CssState, StyleScope, applyInlineSyle } from "ui/styling/style-scope";
import { KeyframeAnimation } from "ui/animation/keyframe-animation";
import { enabled as traceEnabled, write as traceWrite, categories as traceCategories, notifyEvent as traceNotifyEvent } from "trace";
import { enabled as traceEnabled, write as traceWrite, categories as traceCategories, notifyEvent as traceNotifyEvent, isCategorySet } from "trace";
export { KeyframeAnimation, Observable, EventData, Binding, BindingOptions, Bindable, isIOS, gestureFromString, traceEnabled, traceWrite, traceCategories, traceNotifyEvent };
export {
KeyframeAnimation, Observable, EventData, Binding, BindingOptions, Bindable, isIOS, isAndroid,
gestureFromString, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, isCategorySet
};
export * from "./properties";
let defaultBindingSource = {};
@@ -92,7 +95,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
return null;
}
protected onLoaded() {
public onLoaded() {
this._isLoaded = true;
this._loadEachChildView();
this._applyStyleFromScope();
@@ -112,7 +115,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
}
}
protected onUnloaded() {
public onUnloaded() {
this._setCssState(null);
this._unloadEachChildView();
this._isLoaded = false;

View File

@@ -1894,9 +1894,9 @@ opacityProperty.register(Style);
export const colorProperty = new InheritedCssProperty<Style, Color>({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
colorProperty.register(Style);
export let fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default });
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default });
export let fontFamilyProperty = new InheritedCssProperty<Style, string>({
export const fontFamilyProperty = new InheritedCssProperty<Style, string>({
name: "fontFamily", cssName: "font-family", valueChanged: (target, newValue) => {
let currentFont = target.fontInternal;
if (currentFont.fontFamily !== newValue) {
@@ -1906,7 +1906,7 @@ export let fontFamilyProperty = new InheritedCssProperty<Style, string>({
});
fontFamilyProperty.register(Style);
export let fontSizeProperty = new InheritedCssProperty<Style, number>({
export const fontSizeProperty = new InheritedCssProperty<Style, number>({
name: "fontSize", cssName: "font-size", valueChanged: (target, newValue) => {
let currentFont = target.fontInternal;
if (currentFont.fontSize !== newValue) {
@@ -1917,7 +1917,7 @@ export let fontSizeProperty = new InheritedCssProperty<Style, number>({
});
fontSizeProperty.register(Style);
export let fontStyleProperty = new InheritedCssProperty<Style, "normal" | "italic">({
export const fontStyleProperty = new InheritedCssProperty<Style, "normal" | "italic">({
name: "fontStyle", cssName: "font-style", defaultValue: "normal", valueChanged: (target, newValue) => {
if (!(newValue === "normal" || newValue === "italic")) {
throw new Error(`font-style should be 'normal' or 'italic'. value: ${newValue}`)
@@ -1931,7 +1931,7 @@ export let fontStyleProperty = new InheritedCssProperty<Style, "normal" | "itali
});
fontStyleProperty.register(Style);
export let fontWeightProperty = new InheritedCssProperty<Style, "100" | "200" | "300" | "normal" | "400" | "500" | "600" | "bold" | "700" | "800" | "900">({
export const fontWeightProperty = new InheritedCssProperty<Style, "100" | "200" | "300" | "normal" | "400" | "500" | "600" | "bold" | "700" | "800" | "900">({
name: "fontWeight", cssName: "font-weight", defaultValue: "normal", valueChanged: (target, newValue) => {
if (!newValue) {
console.trace();
@@ -1953,7 +1953,7 @@ export let fontWeightProperty = new InheritedCssProperty<Style, "100" | "200" |
});
fontWeightProperty.register(Style);
export let fontProperty = new ShorthandProperty<Style>({
export const fontProperty = new ShorthandProperty<Style>({
name: "font", cssName: "font",
getter: function (this: Style) {
return `${this.fontStyle} ${this.fontWeight} ${this.fontSize} ${this.fontFamily}`;

View File

@@ -76,7 +76,7 @@ export class View extends ViewCommon {
}
}
protected onLoaded() {
public onLoaded() {
super.onLoaded();
this.setOnTouchListener();
}
@@ -343,7 +343,7 @@ export class View extends ViewCommon {
}
}
public getLocationRelativeTo(otherView: View): Point {
public getLocationRelativeTo(otherView: ViewCommon): Point {
if (!this._nativeView || !this._nativeView.getWindowToken() ||
!otherView._nativeView || !otherView._nativeView.getWindowToken() ||
this._nativeView.getWindowToken() !== otherView._nativeView.getWindowToken()) {
@@ -1075,7 +1075,7 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
this._viewGroup = new org.nativescript.widgets.ContentLayout(this._context);
}
public _addViewToNativeVisualTree(child: View, atIndex: number = -1): boolean {
public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean {
super._addViewToNativeVisualTree(child);
if (this.nativeView && child.nativeView) {
@@ -1089,7 +1089,7 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
return false;
}
public _removeViewFromNativeVisualTree(child: View): void {
public _removeViewFromNativeVisualTree(child: ViewCommon): void {
super._removeViewFromNativeVisualTree(child);
if (this._nativeView && child._nativeView) {
@@ -1100,4 +1100,4 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
}
}
}
}
}

View File

@@ -22,12 +22,12 @@ export class View extends ViewCommon {
private _cachedFrame: CGRect;
private _suspendCATransaction = false;
public _addViewCore(view: ViewDefinition, atIndex?: number) {
public _addViewCore(view: ViewCommon, atIndex?: number) {
super._addViewCore(view, atIndex);
this.requestLayout();
}
public _removeViewCore(view: ViewDefinition) {
public _removeViewCore(view: ViewCommon) {
super._removeViewCore(view);
// TODO: Detach from the context?
view._onDetached();