mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Fix animations and lots of cyclic requires
This commit is contained in:
1
tns-core-modules/tns-core-modules.base.d.ts
vendored
1
tns-core-modules/tns-core-modules.base.d.ts
vendored
@ -86,7 +86,6 @@
|
||||
/// <reference path="ui/styling/styling.d.ts" />
|
||||
/// <reference path="ui/switch/switch.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-field/text-field.d.ts" />
|
||||
/// <reference path="ui/text-view/text-view.d.ts" />
|
||||
|
@ -69,7 +69,9 @@ export abstract class AnimationBase implements AnimationBaseDefinition {
|
||||
|
||||
this._propertyAnimations = new Array<PropertyAnimation>();
|
||||
for (let i = 0, length = animationDefinitions.length; i < length; i++) {
|
||||
if (animationDefinitions[i].curve){
|
||||
animationDefinitions[i].curve = this._resolveAnimationCurve(animationDefinitions[i].curve);
|
||||
}
|
||||
this._propertyAnimations = this._propertyAnimations.concat(AnimationBase._createPropertyAnimations(animationDefinitions[i]));
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ import {
|
||||
AnimationBase, Properties, PropertyAnimation, CubicBezierAnimationCurve, AnimationPromise,
|
||||
opacityProperty, backgroundColorProperty, rotateProperty,
|
||||
translateXProperty, translateYProperty,
|
||||
scaleXProperty, scaleYProperty, Color, layout, traceWrite, traceEnabled, traceCategories
|
||||
scaleXProperty, scaleYProperty, Color, traceWrite, traceEnabled, traceCategories
|
||||
} from "./animation-common";
|
||||
|
||||
import { CacheLayerType } from "utils/utils";
|
||||
import { CacheLayerType, layout } from "utils/utils";
|
||||
import lazy from "utils/lazy";
|
||||
|
||||
export * from "./animation-common";
|
||||
@ -71,11 +71,12 @@ export function _resolveAnimationCurve(curve: string | CubicBezierAnimationCurve
|
||||
}
|
||||
if (curve instanceof CubicBezierAnimationCurve) {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
if (!propertyAnimation.target) {
|
||||
throw new Error("Animation target cannot be null or undefined!");
|
||||
if (propertyAnimation.target === null || propertyAnimation.target === undefined) {
|
||||
throw new Error(`Animation target cannot be null or undefined; property: ${propertyAnimation.property}; value: ${propertyAnimation.value};`);
|
||||
}
|
||||
|
||||
if (!propertyAnimation.property) {
|
||||
throw new Error("Animation property cannot be null or undefined!");
|
||||
if (propertyAnimation.property === null || propertyAnimation.property === undefined) {
|
||||
throw new Error(`Animation property cannot be null or undefined; target: ${propertyAnimation.target}; value: ${propertyAnimation.value};`);
|
||||
}
|
||||
|
||||
if (!propertyAnimation.value) {
|
||||
throw new Error("Animation value cannot be null or undefined!");
|
||||
if (propertyAnimation.value === null || propertyAnimation.value === undefined) {
|
||||
throw new Error(`Animation value cannot be null or undefined; target: ${propertyAnimation.target}; property: ${propertyAnimation.property};`);
|
||||
}
|
||||
|
||||
let nativeArray;
|
||||
|
@ -136,7 +136,9 @@ export function _resolveAnimationCurve(curve: string | CubicBezierAnimationCurve
|
||||
let animationCurve = <CubicBezierAnimationCurve>curve;
|
||||
return CAMediaTimingFunction.functionWithControlPoints(animationCurve.x1, animationCurve.y1, animationCurve.x2, animationCurve.y2);
|
||||
}
|
||||
return undefined;
|
||||
else {
|
||||
throw new Error(`Invalid animation curve: ${curve}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,8 @@ import {
|
||||
KeyframeAnimation as KeyframeAnimationDefinition
|
||||
} 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 {
|
||||
public property: string;
|
||||
|
@ -4,14 +4,21 @@ import { Property, InheritedProperty, Style, clearInheritedProperties, propagate
|
||||
import { Binding, BindingOptions, Bindable } from "ui/core/bindable";
|
||||
import { isIOS, isAndroid } from "platform";
|
||||
import { fromString as gestureFromString } from "ui/gestures";
|
||||
import { CssState, StyleScope, applyInlineStyle } from "ui/styling/style-scope";
|
||||
import { SelectorCore } from "ui/styling/css-selector";
|
||||
import { KeyframeAnimation } from "ui/animation/keyframe-animation";
|
||||
|
||||
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 {
|
||||
KeyframeAnimation, Observable, EventData, Binding, BindingOptions, Bindable, isIOS, isAndroid,
|
||||
Observable, EventData, Binding, BindingOptions, Bindable, isIOS, isAndroid,
|
||||
gestureFromString, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, isCategorySet
|
||||
};
|
||||
export * from "./properties";
|
||||
@ -113,7 +120,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
public _context: any;
|
||||
public _isAddedToNativeVisualTree: any;
|
||||
|
||||
public _cssState: CssState;
|
||||
public _cssState: ssm.CssState;
|
||||
constructor() {
|
||||
super();
|
||||
this._domId = viewIdCounter++;
|
||||
@ -202,12 +209,12 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
if (!rootPage || !rootPage.isLoaded) {
|
||||
return;
|
||||
}
|
||||
let scope: StyleScope = (<any>rootPage)._getStyleScope();
|
||||
let scope: ssm.StyleScope = (<any>rootPage)._getStyleScope();
|
||||
scope.applySelectors(this);
|
||||
}
|
||||
|
||||
// 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;
|
||||
this._cssState = next;
|
||||
|
||||
@ -333,7 +340,8 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
if (typeof inlineStyle === "string") {
|
||||
try {
|
||||
// this.style._beginUpdate();
|
||||
applyInlineStyle(this, inlineStyle);
|
||||
ensureStyleScopeModule();
|
||||
styleScopeModule.applyInlineStyle(this, inlineStyle);
|
||||
} finally {
|
||||
// this.style._endUpdate();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { View as ViewDefinition, Point, Size } from "ui/core/view";
|
||||
import { Color } from "color";
|
||||
import { Animation, AnimationPromise } from "ui/animation";
|
||||
import { Source } from "utils/debug";
|
||||
import { Background } from "ui/styling/background";
|
||||
import {
|
||||
@ -10,7 +9,6 @@ import {
|
||||
} from "./view-base";
|
||||
import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures";
|
||||
import { Font, parseFont, FontStyle, FontWeight } from "ui/styling/font";
|
||||
import { fontSizeConverter } from "../styling/converters";
|
||||
|
||||
// Only types:
|
||||
import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "ui/layouts/flexbox-layout";
|
||||
@ -24,10 +22,17 @@ export * from "./view-base";
|
||||
|
||||
export {
|
||||
GestureTypes, GesturesObserver, GestureEventData,
|
||||
Animation, AnimationPromise,
|
||||
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) => {
|
||||
// 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();
|
||||
}
|
||||
|
||||
public createAnimation(animation: any): any {
|
||||
public createAnimation(animation: any): am.Animation {
|
||||
ensureAnimationModule();
|
||||
animation.target = this;
|
||||
return new Animation([animation]);
|
||||
return new animationModule.Animation([animation]);
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
@ -1983,7 +1989,7 @@ const fontProperty = new ShorthandProperty<Style, string>({
|
||||
];
|
||||
} else {
|
||||
let font = parseFont(value);
|
||||
let fontSize = fontSizeConverter(font.fontSize);
|
||||
let fontSize = parseFloat(font.fontSize);
|
||||
|
||||
return [
|
||||
[fontStyleProperty, font.fontStyle],
|
||||
|
3
tns-core-modules/ui/core/view.d.ts
vendored
3
tns-core-modules/ui/core/view.d.ts
vendored
@ -1,6 +1,5 @@
|
||||
declare module "ui/core/view" {
|
||||
import { GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction } from "ui/gestures";
|
||||
import { Animation, AnimationDefinition, AnimationPromise } from "ui/animation";
|
||||
import {
|
||||
ViewBase, Property, CssProperty, InheritedCssProperty, Style, EventData, ShorthandProperty
|
||||
} from "ui/core/view-base";
|
||||
@ -10,9 +9,9 @@ declare module "ui/core/view" {
|
||||
|
||||
export {
|
||||
GestureTypes, GesturesObserver, GestureEventData, TouchGestureEventData, TouchAction,
|
||||
Animation, AnimationDefinition, AnimationPromise,
|
||||
Background, Font, Color
|
||||
}
|
||||
import { Animation, AnimationDefinition, AnimationPromise } from "ui/animation";
|
||||
|
||||
export * from "ui/core/view-base";
|
||||
|
||||
|
@ -1,13 +1,26 @@
|
||||
import { ViewBase, resetCSSProperties } from "ui/core/view-base";
|
||||
import { SyntaxTree, Keyframes, parse as parseCss, Node } from "css";
|
||||
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 { File, knownFolders, path } from "file-system";
|
||||
import { CssAnimationParser } from "./css-animation-parser";
|
||||
|
||||
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");
|
||||
|
||||
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) {
|
||||
ensureKeyframeAnimationModule();
|
||||
for (let animationInfo of ruleAnimations) {
|
||||
let animation = KeyframeAnimation.keyframeAnimationFromInfo(animationInfo);
|
||||
let animation = keyframeAnimationModule.KeyframeAnimation.keyframeAnimationFromInfo(animationInfo);
|
||||
if (animation) {
|
||||
view._registerAnimation(animation);
|
||||
animation.play(view)
|
||||
@ -112,11 +126,13 @@ export class StyleScope {
|
||||
this.ensureSelectors();
|
||||
}
|
||||
|
||||
public getKeyframeAnimationWithName(animationName: string): KeyframeAnimationInfo {
|
||||
public getKeyframeAnimationWithName(animationName: string): kam.KeyframeAnimationInfo {
|
||||
let keyframes = this._keyframes[animationName];
|
||||
if (keyframes !== undefined) {
|
||||
let animation = new KeyframeAnimationInfo();
|
||||
animation.keyframes = CssAnimationParser.keyframesArrayFromCSS(keyframes);
|
||||
ensureKeyframeAnimationModule();
|
||||
let animation = new keyframeAnimationModule.KeyframeAnimationInfo();
|
||||
ensureCssAnimationParserModule();
|
||||
animation.keyframes = cssAnimationParserModule.CssAnimationParser.keyframesArrayFromCSS(keyframes);
|
||||
return animation;
|
||||
}
|
||||
return undefined;
|
||||
@ -212,7 +228,10 @@ export class StyleScope {
|
||||
(<Keyframes[]>nodes.filter(isKeyframe)).forEach(node => keyframes[node.name] = node);
|
||||
|
||||
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;
|
||||
}
|
||||
@ -225,19 +244,20 @@ export class StyleScope {
|
||||
private _applyKeyframesOnSelectors() {
|
||||
for (let i = this._mergedCssSelectors.length - 1; i >= 0; i--) {
|
||||
let ruleset = this._mergedCssSelectors[i];
|
||||
let animations = ruleset[animationsSymbol];
|
||||
if (animations !== undefined) {
|
||||
let animations: kam.KeyframeAnimationInfo[] = ruleset[animationsSymbol];
|
||||
if (animations !== undefined && animations.length) {
|
||||
ensureCssAnimationParserModule();
|
||||
for (let animation of animations) {
|
||||
let keyframe = this._keyframes[animation.name];
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
// }
|
||||
// }
|
@ -1,5 +0,0 @@
|
||||
// declare module "ui/text-base/text-base-styler" {
|
||||
// export class TextBaseStyler {
|
||||
// public static registerHandlers();
|
||||
// }
|
||||
// }
|
@ -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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
Reference in New Issue
Block a user