Fix animations and lots of cyclic requires

This commit is contained in:
Rossen Hristov
2017-01-13 14:41:32 +02:00
parent dad5e79df3
commit c3327ea52f
12 changed files with 80 additions and 413 deletions

View File

@ -86,7 +86,6 @@
/// <reference path="ui/styling/styling.d.ts" /> /// <reference path="ui/styling/styling.d.ts" />
/// <reference path="ui/switch/switch.d.ts" /> /// <reference path="ui/switch/switch.d.ts" />
/// <reference path="ui/tab-view/tab-view.d.ts" /> /// <reference path="ui/tab-view/tab-view.d.ts" />
/// <reference path="ui/text-base/text-base-styler.d.ts" />
/// <reference path="ui/text-base/text-base.d.ts" /> /// <reference path="ui/text-base/text-base.d.ts" />
/// <reference path="ui/text-field/text-field.d.ts" /> /// <reference path="ui/text-field/text-field.d.ts" />
/// <reference path="ui/text-view/text-view.d.ts" /> /// <reference path="ui/text-view/text-view.d.ts" />

View File

@ -69,7 +69,9 @@ export abstract class AnimationBase implements AnimationBaseDefinition {
this._propertyAnimations = new Array<PropertyAnimation>(); this._propertyAnimations = new Array<PropertyAnimation>();
for (let i = 0, length = animationDefinitions.length; i < length; i++) { for (let i = 0, length = animationDefinitions.length; i < length; i++) {
animationDefinitions[i].curve = this._resolveAnimationCurve(animationDefinitions[i].curve); if (animationDefinitions[i].curve){
animationDefinitions[i].curve = this._resolveAnimationCurve(animationDefinitions[i].curve);
}
this._propertyAnimations = this._propertyAnimations.concat(AnimationBase._createPropertyAnimations(animationDefinitions[i])); this._propertyAnimations = this._propertyAnimations.concat(AnimationBase._createPropertyAnimations(animationDefinitions[i]));
} }

View File

@ -3,10 +3,10 @@ import {
AnimationBase, Properties, PropertyAnimation, CubicBezierAnimationCurve, AnimationPromise, AnimationBase, Properties, PropertyAnimation, CubicBezierAnimationCurve, AnimationPromise,
opacityProperty, backgroundColorProperty, rotateProperty, opacityProperty, backgroundColorProperty, rotateProperty,
translateXProperty, translateYProperty, translateXProperty, translateYProperty,
scaleXProperty, scaleYProperty, Color, layout, traceWrite, traceEnabled, traceCategories scaleXProperty, scaleYProperty, Color, traceWrite, traceEnabled, traceCategories
} from "./animation-common"; } from "./animation-common";
import { CacheLayerType } from "utils/utils"; import { CacheLayerType, layout } from "utils/utils";
import lazy from "utils/lazy"; import lazy from "utils/lazy";
export * from "./animation-common"; export * from "./animation-common";
@ -71,11 +71,12 @@ export function _resolveAnimationCurve(curve: string | CubicBezierAnimationCurve
} }
if (curve instanceof CubicBezierAnimationCurve) { if (curve instanceof CubicBezierAnimationCurve) {
return (<any>android).support.v4.view.animation.PathInterpolatorCompat.create(curve.x1, curve.y1, curve.x2, curve.y2); return (<any>android).support.v4.view.animation.PathInterpolatorCompat.create(curve.x1, curve.y1, curve.x2, curve.y2);
} else if (curve instanceof android.view.animation.Interpolator) { }
else if (curve instanceof android.view.animation.Interpolator) {
return curve; return curve;
} }
else { else {
throw new Error("Invalid android.view.animation.Interpolator."); throw new Error(`Invalid animation curve: ${curve}`);
} }
} }
} }
@ -206,16 +207,16 @@ export class Animation extends AnimationBase {
traceWrite("Creating ObjectAnimator(s) for animation: " + Animation._getAnimationInfo(propertyAnimation) + "...", traceCategories.Animation); traceWrite("Creating ObjectAnimator(s) for animation: " + Animation._getAnimationInfo(propertyAnimation) + "...", traceCategories.Animation);
} }
if (!propertyAnimation.target) { if (propertyAnimation.target === null || propertyAnimation.target === undefined) {
throw new Error("Animation target cannot be null or undefined!"); throw new Error(`Animation target cannot be null or undefined; property: ${propertyAnimation.property}; value: ${propertyAnimation.value};`);
} }
if (!propertyAnimation.property) { if (propertyAnimation.property === null || propertyAnimation.property === undefined) {
throw new Error("Animation property cannot be null or undefined!"); throw new Error(`Animation property cannot be null or undefined; target: ${propertyAnimation.target}; value: ${propertyAnimation.value};`);
} }
if (!propertyAnimation.value) { if (propertyAnimation.value === null || propertyAnimation.value === undefined) {
throw new Error("Animation value cannot be null or undefined!"); throw new Error(`Animation value cannot be null or undefined; target: ${propertyAnimation.target}; property: ${propertyAnimation.property};`);
} }
let nativeArray; let nativeArray;

View File

@ -136,7 +136,9 @@ export function _resolveAnimationCurve(curve: string | CubicBezierAnimationCurve
let animationCurve = <CubicBezierAnimationCurve>curve; let animationCurve = <CubicBezierAnimationCurve>curve;
return CAMediaTimingFunction.functionWithControlPoints(animationCurve.x1, animationCurve.y1, animationCurve.x2, animationCurve.y2); return CAMediaTimingFunction.functionWithControlPoints(animationCurve.x1, animationCurve.y1, animationCurve.x2, animationCurve.y2);
} }
return undefined; else {
throw new Error(`Invalid animation curve: ${curve}`);
}
} }
} }

View File

@ -5,7 +5,8 @@ import {
KeyframeAnimation as KeyframeAnimationDefinition KeyframeAnimation as KeyframeAnimationDefinition
} from "ui/animation/keyframe-animation"; } from "ui/animation/keyframe-animation";
import { View, unsetValue, Animation } from "ui/core/view"; import { View, unsetValue } from "ui/core/view";
import { Animation } from "ui/animation";
export class KeyframeDeclaration implements KeyframeDeclarationDefinition { export class KeyframeDeclaration implements KeyframeDeclarationDefinition {
public property: string; public property: string;

View File

@ -4,14 +4,21 @@ import { Property, InheritedProperty, Style, clearInheritedProperties, propagate
import { Binding, BindingOptions, Bindable } from "ui/core/bindable"; import { Binding, BindingOptions, Bindable } from "ui/core/bindable";
import { isIOS, isAndroid } from "platform"; import { isIOS, isAndroid } from "platform";
import { fromString as gestureFromString } from "ui/gestures"; import { fromString as gestureFromString } from "ui/gestures";
import { CssState, StyleScope, applyInlineStyle } from "ui/styling/style-scope";
import { SelectorCore } from "ui/styling/css-selector"; import { SelectorCore } from "ui/styling/css-selector";
import { KeyframeAnimation } from "ui/animation/keyframe-animation"; import { KeyframeAnimation } from "ui/animation/keyframe-animation";
import { enabled as traceEnabled, write as traceWrite, categories as traceCategories, notifyEvent as traceNotifyEvent, isCategorySet } from "trace"; import { enabled as traceEnabled, write as traceWrite, categories as traceCategories, notifyEvent as traceNotifyEvent, isCategorySet } from "trace";
import * as ssm from "ui/styling/style-scope";
let styleScopeModule: typeof ssm;
function ensureStyleScopeModule() {
if (!styleScopeModule){
styleScopeModule = require("ui/styling/style-scope");
}
}
export { export {
KeyframeAnimation, Observable, EventData, Binding, BindingOptions, Bindable, isIOS, isAndroid, Observable, EventData, Binding, BindingOptions, Bindable, isIOS, isAndroid,
gestureFromString, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, isCategorySet gestureFromString, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, isCategorySet
}; };
export * from "./properties"; export * from "./properties";
@ -113,7 +120,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
public _context: any; public _context: any;
public _isAddedToNativeVisualTree: any; public _isAddedToNativeVisualTree: any;
public _cssState: CssState; public _cssState: ssm.CssState;
constructor() { constructor() {
super(); super();
this._domId = viewIdCounter++; this._domId = viewIdCounter++;
@ -202,12 +209,12 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
if (!rootPage || !rootPage.isLoaded) { if (!rootPage || !rootPage.isLoaded) {
return; return;
} }
let scope: StyleScope = (<any>rootPage)._getStyleScope(); let scope: ssm.StyleScope = (<any>rootPage)._getStyleScope();
scope.applySelectors(this); scope.applySelectors(this);
} }
// TODO: Make sure the state is set to null and this is called on unloaded to clean up change listeners... // TODO: Make sure the state is set to null and this is called on unloaded to clean up change listeners...
_setCssState(next: CssState): void { _setCssState(next: ssm.CssState): void {
const previous = this._cssState; const previous = this._cssState;
this._cssState = next; this._cssState = next;
@ -333,7 +340,8 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
if (typeof inlineStyle === "string") { if (typeof inlineStyle === "string") {
try { try {
// this.style._beginUpdate(); // this.style._beginUpdate();
applyInlineStyle(this, inlineStyle); ensureStyleScopeModule();
styleScopeModule.applyInlineStyle(this, inlineStyle);
} finally { } finally {
// this.style._endUpdate(); // this.style._endUpdate();
} }

View File

@ -1,6 +1,5 @@
import { View as ViewDefinition, Point, Size } from "ui/core/view"; import { View as ViewDefinition, Point, Size } from "ui/core/view";
import { Color } from "color"; import { Color } from "color";
import { Animation, AnimationPromise } from "ui/animation";
import { Source } from "utils/debug"; import { Source } from "utils/debug";
import { Background } from "ui/styling/background"; import { Background } from "ui/styling/background";
import { import {
@ -10,7 +9,6 @@ import {
} from "./view-base"; } from "./view-base";
import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures"; import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures";
import { Font, parseFont, FontStyle, FontWeight } from "ui/styling/font"; import { Font, parseFont, FontStyle, FontWeight } from "ui/styling/font";
import { fontSizeConverter } from "../styling/converters";
// Only types: // Only types:
import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "ui/layouts/flexbox-layout"; import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "ui/layouts/flexbox-layout";
@ -24,10 +22,17 @@ export * from "./view-base";
export { export {
GestureTypes, GesturesObserver, GestureEventData, GestureTypes, GesturesObserver, GestureEventData,
Animation, AnimationPromise,
Background, Font, Color Background, Font, Color
} }
import * as am from "ui/animation";
let animationModule: typeof am;
function ensureAnimationModule() {
if (!animationModule){
animationModule = require("ui/animation");
}
}
// registerSpecialProperty("class", (instance: ViewDefinition, propertyValue: string) => { // registerSpecialProperty("class", (instance: ViewDefinition, propertyValue: string) => {
// instance.className = propertyValue; // instance.className = propertyValue;
// }); // });
@ -831,13 +836,14 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
}; };
} }
public animate(animation: any): AnimationPromise { public animate(animation: any): am.AnimationPromise {
return this.createAnimation(animation).play(); return this.createAnimation(animation).play();
} }
public createAnimation(animation: any): any { public createAnimation(animation: any): am.Animation {
ensureAnimationModule();
animation.target = this; animation.target = this;
return new Animation([animation]); return new animationModule.Animation([animation]);
} }
public toString(): string { public toString(): string {
@ -1983,7 +1989,7 @@ const fontProperty = new ShorthandProperty<Style, string>({
]; ];
} else { } else {
let font = parseFont(value); let font = parseFont(value);
let fontSize = fontSizeConverter(font.fontSize); let fontSize = parseFloat(font.fontSize);
return [ return [
[fontStyleProperty, font.fontStyle], [fontStyleProperty, font.fontStyle],

View File

@ -1,6 +1,5 @@
declare module "ui/core/view" { declare module "ui/core/view" {
import { GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction } from "ui/gestures"; import { GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction } from "ui/gestures";
import { Animation, AnimationDefinition, AnimationPromise } from "ui/animation";
import { import {
ViewBase, Property, CssProperty, InheritedCssProperty, Style, EventData, ShorthandProperty ViewBase, Property, CssProperty, InheritedCssProperty, Style, EventData, ShorthandProperty
} from "ui/core/view-base"; } from "ui/core/view-base";
@ -10,9 +9,9 @@ declare module "ui/core/view" {
export { export {
GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction, GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction,
Animation, AnimationDefinition, AnimationPromise,
Background, Font, Color Background, Font, Color
} }
import { Animation, AnimationDefinition, AnimationPromise } from "ui/animation";
export * from "ui/core/view-base"; export * from "ui/core/view-base";

View File

@ -1,13 +1,26 @@
import { ViewBase, resetCSSProperties } from "ui/core/view-base"; import { ViewBase, resetCSSProperties } from "ui/core/view-base";
import { SyntaxTree, Keyframes, parse as parseCss, Node } from "css"; import { SyntaxTree, Keyframes, parse as parseCss, Node } from "css";
import { RuleSet, SelectorsMap, SelectorCore, SelectorsMatch, ChangeMap, fromAstNodes } from "ui/styling/css-selector"; import { RuleSet, SelectorsMap, SelectorCore, SelectorsMatch, ChangeMap, fromAstNodes } from "ui/styling/css-selector";
import { KeyframeAnimationInfo, KeyframeAnimation } from "ui/animation/keyframe-animation";
import { write as traceWrite, categories as traceCategories, messageType as traceMessageType } from "trace"; import { write as traceWrite, categories as traceCategories, messageType as traceMessageType } from "trace";
import { File, knownFolders, path } from "file-system"; import { File, knownFolders, path } from "file-system";
import { CssAnimationParser } from "./css-animation-parser";
import * as application from "application"; import * as application from "application";
import * as kam from "ui/animation/keyframe-animation";
let keyframeAnimationModule: typeof kam;
function ensureKeyframeAnimationModule() {
if (!keyframeAnimationModule){
keyframeAnimationModule = require("ui/animation/keyframe-animation");
}
}
import * as capm from "./css-animation-parser";
let cssAnimationParserModule: typeof capm;
function ensureCssAnimationParserModule() {
if (!cssAnimationParserModule){
cssAnimationParserModule = require("./css-animation-parser");
}
}
const animationsSymbol: symbol = Symbol("animations"); const animationsSymbol: symbol = Symbol("animations");
let pattern: RegExp = /('|")(.*?)\1/; let pattern: RegExp = /('|")(.*?)\1/;
@ -47,10 +60,11 @@ export class CssState {
} }
}); });
let ruleAnimations: KeyframeAnimationInfo[] = ruleset[animationsSymbol]; let ruleAnimations: kam.KeyframeAnimationInfo[] = ruleset[animationsSymbol];
if (ruleAnimations && view.isLoaded && view.nativeView !== undefined) { if (ruleAnimations && view.isLoaded && view.nativeView !== undefined) {
ensureKeyframeAnimationModule();
for (let animationInfo of ruleAnimations) { for (let animationInfo of ruleAnimations) {
let animation = KeyframeAnimation.keyframeAnimationFromInfo(animationInfo); let animation = keyframeAnimationModule.KeyframeAnimation.keyframeAnimationFromInfo(animationInfo);
if (animation) { if (animation) {
view._registerAnimation(animation); view._registerAnimation(animation);
animation.play(view) animation.play(view)
@ -112,11 +126,13 @@ export class StyleScope {
this.ensureSelectors(); this.ensureSelectors();
} }
public getKeyframeAnimationWithName(animationName: string): KeyframeAnimationInfo { public getKeyframeAnimationWithName(animationName: string): kam.KeyframeAnimationInfo {
let keyframes = this._keyframes[animationName]; let keyframes = this._keyframes[animationName];
if (keyframes !== undefined) { if (keyframes !== undefined) {
let animation = new KeyframeAnimationInfo(); ensureKeyframeAnimationModule();
animation.keyframes = CssAnimationParser.keyframesArrayFromCSS(keyframes); let animation = new keyframeAnimationModule.KeyframeAnimationInfo();
ensureCssAnimationParserModule();
animation.keyframes = cssAnimationParserModule.CssAnimationParser.keyframesArrayFromCSS(keyframes);
return animation; return animation;
} }
return undefined; return undefined;
@ -212,7 +228,10 @@ export class StyleScope {
(<Keyframes[]>nodes.filter(isKeyframe)).forEach(node => keyframes[node.name] = node); (<Keyframes[]>nodes.filter(isKeyframe)).forEach(node => keyframes[node.name] = node);
let rulesets = fromAstNodes(nodes); let rulesets = fromAstNodes(nodes);
rulesets.forEach(rule => rule[animationsSymbol] = CssAnimationParser.keyframeAnimationsFromCSSDeclarations(rule.declarations)); if (rulesets && rulesets.length){
ensureCssAnimationParserModule();
rulesets.forEach(rule => rule[animationsSymbol] = cssAnimationParserModule.CssAnimationParser.keyframeAnimationsFromCSSDeclarations(rule.declarations));
}
return rulesets; return rulesets;
} }
@ -225,19 +244,20 @@ export class StyleScope {
private _applyKeyframesOnSelectors() { private _applyKeyframesOnSelectors() {
for (let i = this._mergedCssSelectors.length - 1; i >= 0; i--) { for (let i = this._mergedCssSelectors.length - 1; i >= 0; i--) {
let ruleset = this._mergedCssSelectors[i]; let ruleset = this._mergedCssSelectors[i];
let animations = ruleset[animationsSymbol]; let animations: kam.KeyframeAnimationInfo[] = ruleset[animationsSymbol];
if (animations !== undefined) { if (animations !== undefined && animations.length) {
ensureCssAnimationParserModule();
for (let animation of animations) { for (let animation of animations) {
let keyframe = this._keyframes[animation.name]; let keyframe = this._keyframes[animation.name];
if (keyframe !== undefined) { if (keyframe !== undefined) {
animation.keyframes = CssAnimationParser.keyframesArrayFromCSS(keyframe); animation.keyframes = cssAnimationParserModule.CssAnimationParser.keyframesArrayFromCSS(keyframe);
} }
} }
} }
} }
} }
public getAnimations(ruleset: RuleSet): KeyframeAnimationInfo[] { public getAnimations(ruleset: RuleSet): kam.KeyframeAnimationInfo[] {
return ruleset[animationsSymbol]; return ruleset[animationsSymbol];
} }
} }

View File

@ -1,165 +0,0 @@
// import * as view from "ui/core/view";
// import * as utils from "utils/utils";
// import * as style from "ui/styling/style";
// import * as font from "ui/styling/font";
// import * as enums from "ui/enums";
// import {device} from "platform";
// export class TextBaseStyler implements style.Styler {
// // color
// private static setColorProperty(view: view.View, newValue: any) {
// (<android.widget.TextView>view._nativeView).setTextColor(newValue);
// }
// private static resetColorProperty(view: view.View, nativeValue: any) {
// (<android.widget.TextView>view._nativeView).setTextColor(nativeValue);
// }
// private static getNativeColorValue(view: view.View): any {
// return (<android.widget.TextView>view._nativeView).getTextColors().getDefaultColor();
// }
// // font
// private static setFontInternalProperty(view: view.View, newValue: any, nativeValue?: any) {
// var tv = <android.widget.TextView>view._nativeView;
// var fontValue = <font.Font>newValue;
// var typeface = fontValue.getAndroidTypeface();
// if (typeface) {
// tv.setTypeface(typeface);
// }
// else {
// tv.setTypeface(nativeValue.typeface);
// }
// if (fontValue.fontSize) {
// tv.setTextSize(fontValue.fontSize);
// }
// else {
// tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
// }
// }
// private static resetFontInternalProperty(view: view.View, nativeValue: any) {
// var tv: android.widget.TextView = <android.widget.TextView>view._nativeView;
// if (tv && nativeValue) {
// tv.setTypeface(nativeValue.typeface);
// tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
// }
// }
// private static getNativeFontInternalValue(view: view.View): any {
// var tv: android.widget.TextView = <android.widget.TextView>view._nativeView;
// return {
// typeface: tv.getTypeface(),
// size: tv.getTextSize()
// };
// }
// // text-align
// private static setTextAlignmentProperty(view: view.View, newValue: any) {
// var verticalGravity = view._nativeView.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
// switch (newValue) {
// case enums.TextAlignment.left:
// view._nativeView.setGravity(android.view.Gravity.LEFT | verticalGravity);
// break;
// case enums.TextAlignment.center:
// view._nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
// break;
// case enums.TextAlignment.right:
// view._nativeView.setGravity(android.view.Gravity.RIGHT | verticalGravity);
// break;
// default:
// break;
// }
// }
// private static resetTextAlignmentProperty(view: view.View, nativeValue: any) {
// view._nativeView.setGravity(nativeValue);
// }
// private static getNativeTextAlignmentValue(view: view.View): any {
// return view._nativeView.getGravity();
// }
// // text-decoration
// private static setTextDecorationProperty(view: view.View, newValue: any) {
// utils.ad.setTextDecoration(view._nativeView, newValue);
// }
// private static resetTextDecorationProperty(view: view.View, nativeValue: any) {
// utils.ad.setTextDecoration(view._nativeView, enums.TextDecoration.none);
// }
// // text-transform
// private static setTextTransformProperty(view: view.View, newValue: any) {
// utils.ad.setTextTransform(view, newValue);
// }
// private static resetTextTransformProperty(view: view.View, nativeValue: any) {
// utils.ad.setTextTransform(view, enums.TextTransform.none);
// }
// // white-space
// private static setWhiteSpaceProperty(view: view.View, newValue: any) {
// utils.ad.setWhiteSpace(view._nativeView, newValue);
// }
// private static resetWhiteSpaceProperty(view: view.View, nativeValue: any) {
// utils.ad.setWhiteSpace(view._nativeView, enums.WhiteSpace.normal);
// }
// // letter-spacing
// private static getLetterSpacingProperty(view: view.View): any {
// return view.android.getLetterSpacing();
// }
// private static setLetterSpacingProperty(view: view.View, newValue: any) {
// view.android.setLetterSpacing(newValue);
// }
// private static resetLetterSpacingProperty(view: view.View, nativeValue: any) {
// view.android.setLetterSpacing(nativeValue);
// }
// public static registerHandlers() {
// style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setColorProperty,
// TextBaseStyler.resetColorProperty,
// TextBaseStyler.getNativeColorValue), "TextBase");
// style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setFontInternalProperty,
// TextBaseStyler.resetFontInternalProperty,
// TextBaseStyler.getNativeFontInternalValue), "TextBase");
// style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextAlignmentProperty,
// TextBaseStyler.resetTextAlignmentProperty,
// TextBaseStyler.getNativeTextAlignmentValue), "TextBase");
// style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextDecorationProperty,
// TextBaseStyler.resetTextDecorationProperty), "TextBase");
// style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextTransformProperty,
// TextBaseStyler.resetTextTransformProperty), "TextBase");
// style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setWhiteSpaceProperty,
// TextBaseStyler.resetWhiteSpaceProperty), "TextBase");
// if (parseInt(device.sdkVersion, 10) >= 21) {
// style.registerHandler(style.letterSpacingProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setLetterSpacingProperty,
// TextBaseStyler.resetLetterSpacingProperty,
// TextBaseStyler.getLetterSpacingProperty), "TextBase");
// }
// // !!! IMPORTANT !!! Button registrations were moved to button.android.ts to make sure they
// // are executed when there is a Button on the page: https://github.com/NativeScript/NativeScript/issues/1902
// // If there is no TextBase on the Page, the TextBaseStyler.registerHandlers
// // method was never called because the file it is called from was never required.
// }
// }

View File

@ -1,5 +0,0 @@
// declare module "ui/text-base/text-base-styler" {
// export class TextBaseStyler {
// public static registerHandlers();
// }
// }

View File

@ -1,201 +0,0 @@
// import * as view from "ui/core/view";
// import * as utils from "utils/utils";
// import * as style from "ui/styling/style";
// import * as font from "ui/styling/font";
// import * as enums from "ui/enums";
// import * as types from "utils/types";
// import { TextBase } from "ui/text-base";
// export class TextBaseStyler implements style.Styler {
// // font
// private static setFontInternalProperty(textBase: TextBase, newValue: any, nativeValue?: any) {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// ios.font = (<font.Font>newValue).getUIFont(nativeValue);
// }
// private static resetFontInternalProperty(textBase: TextBase, nativeValue: any) {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// ios.font = nativeValue;
// }
// private static getNativeFontInternalValue(textBase: TextBase): any {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// return ios.font;
// }
// // text-align
// private static setTextAlignmentProperty(textBase: TextBase, newValue: any) {
// utils.ios.setTextAlignment(textBase._nativeView, newValue);
// }
// private static resetTextAlignmentProperty(textBase: TextBase, nativeValue: any) {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// ios.textAlignment = nativeValue;
// }
// private static getNativeTextAlignmentValue(textBase: TextBase): any {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// return ios.textAlignment;
// }
// // text-decoration
// private static setTextDecorationProperty(textBase: TextBase, newValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, newValue, textBase.style.textTransform, textBase.style.letterSpacing);
// }
// private static resetTextDecorationProperty(textBase: TextBase, nativeValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, enums.TextDecoration.none, textBase.style.textTransform, textBase.style.letterSpacing);
// }
// // text-transform
// private static setTextTransformProperty(textBase: TextBase, newValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, textBase.style.textDecoration, newValue, textBase.style.letterSpacing);
// }
// private static resetTextTransformProperty(textBase: TextBase, nativeValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, textBase.style.textDecoration, enums.TextTransform.none, textBase.style.letterSpacing);
// }
// // letter-spacing
// private static setLetterSpacingProperty(textBase: TextBase, newValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, textBase.style.textDecoration, textBase.style.textTransform, newValue);
// }
// private static resetLetterSpacingProperty(textBase: TextBase, nativeValue: any) {
// TextBaseStyler._setTextBaseTextDecorationAndTransform(textBase, textBase.style.textDecoration, textBase.style.textTransform, 0);
// }
// // white-space
// private static setWhiteSpaceProperty(textBase: view.View, newValue: any) {
// utils.ios.setWhiteSpace(textBase._nativeView, newValue);
// }
// private static resetWhiteSpaceProperty(textBase: view.View, nativeValue: any) {
// utils.ios.setWhiteSpace(textBase._nativeView, enums.WhiteSpace.normal);
// }
// // color
// private static setColorProperty(textBase: view.View, newValue: any) {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// ios.textColor = newValue;
// }
// private static resetColorProperty(textBase: view.View, nativeValue: any) {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// ios.textColor = nativeValue;
// }
// private static getNativeColorValue(textBase: view.View): any {
// var ios = <utils.ios.TextUIView>textBase._nativeView;
// return ios.textColor;
// }
// public static registerHandlers() {
// style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setFontInternalProperty,
// TextBaseStyler.resetFontInternalProperty,
// TextBaseStyler.getNativeFontInternalValue), "TextBase");
// style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextAlignmentProperty,
// TextBaseStyler.resetTextAlignmentProperty,
// TextBaseStyler.getNativeTextAlignmentValue), "TextBase");
// style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setColorProperty,
// TextBaseStyler.resetColorProperty,
// TextBaseStyler.getNativeColorValue), "TextBase");
// style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextDecorationProperty,
// TextBaseStyler.resetTextDecorationProperty), "TextBase");
// style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setTextTransformProperty,
// TextBaseStyler.resetTextTransformProperty), "TextBase");
// style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setWhiteSpaceProperty,
// TextBaseStyler.resetWhiteSpaceProperty), "TextBase");
// style.registerHandler(style.letterSpacingProperty, new style.StylePropertyChangedHandler(
// TextBaseStyler.setLetterSpacingProperty,
// TextBaseStyler.resetLetterSpacingProperty), "TextBase");
// }
// private static _setTextBaseTextDecorationAndTransform(textBase: TextBase, decoration: string, transform: string, letterSpacing: number) {
// // if (!textBase["counter"]){
// // textBase["counter"] = 0;
// // }
// // textBase["counter"]++;
// // console.log(`>>> ${textBase["counter"]} ${textBase} ${decoration}; ${transform}; ${letterSpacing}; text: ${textBase.text}; formattedText: ${textBase.formattedText}; isLoaded: ${textBase.isLoaded};`);
// let hasLetterSpacing = types.isNumber(letterSpacing) && !isNaN(letterSpacing);
// let nativeView = <utils.ios.TextUIView>textBase._nativeView;
// if (textBase.formattedText) {
// if (textBase.style.textDecoration.indexOf(enums.TextDecoration.none) === -1) {
// if (textBase.style.textDecoration.indexOf(enums.TextDecoration.underline) !== -1) {
// textBase.formattedText.underline = NSUnderlineStyle.StyleSingle;
// }
// if (textBase.style.textDecoration.indexOf(enums.TextDecoration.lineThrough) !== -1) {
// textBase.formattedText.strikethrough = NSUnderlineStyle.StyleSingle;
// }
// }
// else {
// textBase.formattedText.underline = NSUnderlineStyle.StyleSingle;
// }
// for (let i = 0; i < textBase.formattedText.spans.length; i++) {
// let span = textBase.formattedText.spans.getItem(i);
// span.text = utils.ios.getTransformedText(textBase, span.text, transform);
// }
// if (hasLetterSpacing) {
// let attrText = NSMutableAttributedString.alloc().initWithAttributedString(nativeView.attributedText);
// attrText.addAttributeValueRange(NSKernAttributeName, letterSpacing * (<UIFont>nativeView.font).pointSize, { location: 0, length: attrText.length });
// nativeView.attributedText = attrText;
// }
// }
// else {
// let source = textBase.text;
// let attributes = new Array();
// let range = { location: 0, length: source.length };
// var decorationValues = (decoration + "").split(" ");
// if (decorationValues.indexOf(enums.TextDecoration.none) === -1 || hasLetterSpacing) {
// let dict = new Map<string, number>();
// if (decorationValues.indexOf(enums.TextDecoration.underline) !== -1) {
// dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.StyleSingle);
// }
// if (decorationValues.indexOf(enums.TextDecoration.lineThrough) !== -1) {
// dict.set(NSStrikethroughStyleAttributeName, NSUnderlineStyle.StyleSingle);
// }
// if (hasLetterSpacing) {
// dict.set(NSKernAttributeName, letterSpacing * (<UIFont>nativeView.font).pointSize);
// }
// attributes.push({ attrs: dict, range: NSValue.valueWithRange(range) });
// }
// source = utils.ios.getTransformedText(textBase, source, transform);
// if (attributes.length > 0) {
// let result = NSMutableAttributedString.alloc().initWithString(<string>source);
// for (let i = 0; i < attributes.length; i++) {
// result.setAttributesRange(attributes[i]["attrs"], attributes[i]["range"].rangeValue);
// }
// nativeView.attributedText = result;
// }
// else {
// nativeView.text = source;
// }
// }
// }
// }