mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
stylers removed
This commit is contained in:
170
ui/text-base/text-base-styler.android.ts
Normal file
170
ui/text-base/text-base-styler.android.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
import view = require("ui/core/view");
|
||||
import utils = require("utils/utils");
|
||||
import types = require("utils/types");
|
||||
import style = require("ui/styling/style");
|
||||
import font = require("ui/styling/font");
|
||||
import styling = require("ui/styling");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
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._nativeView, newValue);
|
||||
}
|
||||
|
||||
private static resetTextTransformProperty(view: view.View, nativeValue: any) {
|
||||
utils.ad.setTextTransform(view._nativeView, 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);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// Register the same stylers for Button.
|
||||
// It also derives from TextView but is not under TextBase in our View hierarchy.
|
||||
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setColorProperty,
|
||||
TextBaseStyler.resetColorProperty,
|
||||
TextBaseStyler.getNativeColorValue), "Button");
|
||||
|
||||
style.registerHandler(style.fontInternalProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setFontInternalProperty,
|
||||
TextBaseStyler.resetFontInternalProperty,
|
||||
TextBaseStyler.getNativeFontInternalValue), "Button");
|
||||
|
||||
style.registerHandler(style.textAlignmentProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setTextAlignmentProperty,
|
||||
TextBaseStyler.resetTextAlignmentProperty,
|
||||
TextBaseStyler.getNativeTextAlignmentValue), "Button");
|
||||
|
||||
style.registerHandler(style.textDecorationProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setTextDecorationProperty,
|
||||
TextBaseStyler.resetTextDecorationProperty), "Button");
|
||||
|
||||
style.registerHandler(style.textTransformProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setTextTransformProperty,
|
||||
TextBaseStyler.resetTextTransformProperty), "Button");
|
||||
|
||||
style.registerHandler(style.whiteSpaceProperty, new style.StylePropertyChangedHandler(
|
||||
TextBaseStyler.setWhiteSpaceProperty,
|
||||
TextBaseStyler.resetWhiteSpaceProperty), "Button");
|
||||
}
|
||||
}
|
||||
5
ui/text-base/text-base-styler.d.ts
vendored
Normal file
5
ui/text-base/text-base-styler.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module "ui/text-base/text-base-styler" {
|
||||
export class TextBaseStyler {
|
||||
public static registerHandlers();
|
||||
}
|
||||
}
|
||||
112
ui/text-base/text-base-styler.ios.ts
Normal file
112
ui/text-base/text-base-styler.ios.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import view = require("ui/core/view");
|
||||
import utils = require("utils/utils");
|
||||
import types = require("utils/types");
|
||||
import style = require("ui/styling/style");
|
||||
import font = require("ui/styling/font");
|
||||
import styling = require("ui/styling");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
export class TextBaseStyler implements style.Styler {
|
||||
// font
|
||||
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue?: any) {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
ios.font = (<font.Font>newValue).getUIFont(nativeValue);
|
||||
}
|
||||
|
||||
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
ios.font = nativeValue;
|
||||
}
|
||||
|
||||
private static getNativeFontInternalValue(view: view.View): any {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
return ios.font;
|
||||
}
|
||||
|
||||
// text-align
|
||||
private static setTextAlignmentProperty(view: view.View, newValue: any) {
|
||||
utils.ios.setTextAlignment(view._nativeView, newValue);
|
||||
}
|
||||
|
||||
private static resetTextAlignmentProperty(view: view.View, nativeValue: any) {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
ios.textAlignment = nativeValue;
|
||||
}
|
||||
|
||||
private static getNativeTextAlignmentValue(view: view.View): any {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
return ios.textAlignment;
|
||||
}
|
||||
|
||||
// text-decoration
|
||||
private static setTextDecorationProperty(view: view.View, newValue: any) {
|
||||
utils.ios.setTextDecoration(view._nativeView, newValue);
|
||||
}
|
||||
|
||||
private static resetTextDecorationProperty(view: view.View, nativeValue: any) {
|
||||
utils.ios.setTextDecoration(view._nativeView, enums.TextDecoration.none);
|
||||
}
|
||||
|
||||
// text-transform
|
||||
private static setTextTransformProperty(view: view.View, newValue: any) {
|
||||
utils.ios.setTextTransform(view._nativeView, newValue);
|
||||
}
|
||||
|
||||
private static resetTextTransformProperty(view: view.View, nativeValue: any) {
|
||||
utils.ios.setTextTransform(view._nativeView, enums.TextTransform.none);
|
||||
}
|
||||
|
||||
// white-space
|
||||
private static setWhiteSpaceProperty(view: view.View, newValue: any) {
|
||||
utils.ios.setWhiteSpace(view._nativeView, newValue);
|
||||
}
|
||||
|
||||
private static resetWhiteSpaceProperty(view: view.View, nativeValue: any) {
|
||||
utils.ios.setWhiteSpace(view._nativeView, enums.WhiteSpace.normal);
|
||||
}
|
||||
|
||||
// color
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
ios.textColor = newValue;
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||
var ios = <utils.ios.TextUIView>view._nativeView;
|
||||
ios.textColor = nativeValue;
|
||||
}
|
||||
|
||||
private static getNativeColorValue(view: view.View): any {
|
||||
var ios = <utils.ios.TextUIView>view._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");
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import formattedString = require("text/formatted-string");
|
||||
import * as weakEventListenerModule from "ui/core/weak-event-listener";
|
||||
import tbs = require("ui/text-base/text-base-styler");
|
||||
|
||||
var textProperty = new dependencyObservable.Property(
|
||||
"text",
|
||||
@@ -123,4 +124,6 @@ export class TextBase extends view.View implements definition.TextBase, formatte
|
||||
public _addChildFromBuilder(name: string, value: any): void {
|
||||
formattedString.FormattedString.addFormattedStringToView(this, name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbs.TextBaseStyler.registerHandlers()
|
||||
Reference in New Issue
Block a user