From d795ee94e433f6085ff3c599f14864ee9053b0ff Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Mon, 28 Nov 2016 13:34:15 +0200 Subject: [PATCH] alpha2 --- tns-core-modules/ui/core/view-common.ts | 132 ++ tns-core-modules/ui/core/view.d.ts | 9 +- tns-core-modules/ui/enums/enums.d.ts | 1204 ++++++++--------- tns-core-modules/ui/frame/frame.d.ts | 2 +- tns-core-modules/ui/frame/frame.ios.ts | 27 +- tns-core-modules/ui/gestures/gestures.ios.ts | 6 - tns-core-modules/ui/image/image-common.ts | 2 +- tns-core-modules/ui/image/image.d.ts | 4 +- tns-core-modules/ui/label/label.android.ts | 2 +- tns-core-modules/ui/label/label.ios.ts | 319 ++--- .../ui/list-picker/list-picker-common.ts | 96 +- .../ui/list-picker/list-picker.android.ts | 152 +-- .../ui/list-picker/list-picker.d.ts | 21 +- .../ui/list-picker/list-picker.ios.ts | 57 +- tns-core-modules/ui/styling/style.d.ts | 18 +- tns-core-modules/ui/styling/style.ts | 143 -- .../ui/text-base/text-base-common.ts | 20 +- tns-core-modules/ui/text-base/text-base.d.ts | 14 +- .../ui/text-base/text-base.ios.ts | 21 +- 19 files changed, 1053 insertions(+), 1196 deletions(-) diff --git a/tns-core-modules/ui/core/view-common.ts b/tns-core-modules/ui/core/view-common.ts index 3219e8ac0..212c1e611 100644 --- a/tns-core-modules/ui/core/view-common.ts +++ b/tns-core-modules/ui/core/view-common.ts @@ -11,6 +11,7 @@ import { ViewBase, getEventOrGestureName } from "./view-base"; import { propagateInheritedProperties, clearInheritedProperties, Property, InheritedProperty, CssProperty, ShorthandProperty, InheritedCssProperty } from "./properties"; import { observe, fromString as gestureFromString, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures"; import { isIOS } from "platform"; +import { Font } from "ui/styling/font"; // TODO: Remove this and start using string as source (for android). import { fromFileOrResource, fromBase64, fromUrl } from "image-source"; @@ -2171,3 +2172,134 @@ opacityProperty.register(Style); export const colorProperty = new InheritedCssProperty({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v: string) => new Color(v) }); colorProperty.register(Style); + + +export let fontInternalProperty = new CssProperty({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default }); + +export let fontFamilyProperty = new InheritedCssProperty({ + name: "fontFamily", cssName: "font-family", valueChanged: (target, newValue) => { + let currentFont = target.fontInternal; + if (currentFont.fontFamily !== newValue) { + target.fontInternal = currentFont.withFontFamily(newValue); + } + } +}); +fontFamilyProperty.register(Style); + +export let fontSizeProperty = new InheritedCssProperty({ + name: "fontSize", cssName: "font-size", valueChanged: (target, newValue) => { + let currentFont = target.fontInternal; + if (currentFont.fontSize !== newValue) { + target.fontInternal = currentFont.withFontSize(newValue); + } + }, + valueConverter: (v) => parseFloat(v) +}); +fontSizeProperty.register(Style); + +export let fontStyleProperty = new InheritedCssProperty({ + 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}`) + } + + let currentFont = target.fontInternal; + if (currentFont.fontStyle !== newValue) { + target.fontInternal = currentFont.withFontStyle(newValue); + } + } +}); +fontStyleProperty.register(Style); + +export let fontWeightProperty = new InheritedCssProperty({ + name: "fontWeight", cssName: "font-weight", defaultValue: "normal", valueChanged: (target, newValue) => { + if (!newValue) { + console.trace(); + } + + // TODO: Console.log errors or throw error? + if (!(newValue === "normal" || newValue === "bold" + || newValue === "100" || newValue === "200" || newValue === "300" + || newValue === "400" || newValue === "500" || newValue === "600" + || newValue === "700" || newValue === "800" || newValue === "900")) { + throw new Error(`Invalid font-weight value: ${newValue}`); + } + + let currentFont = target.fontInternal; + if (currentFont.fontWeight !== newValue) { + target.fontInternal = currentFont.withFontWeight(newValue); + } + } +}); +fontWeightProperty.register(Style); + +export let fontProperty = new ShorthandProperty