From 9e597976c12b9d73130214119cd89de2baa49079 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Fri, 26 Jun 2015 16:19:19 +0300 Subject: [PATCH] Fix: PR comments --- ui/core/dependency-observable.d.ts | 4 +++ ui/styling/font.ios.ts | 49 +++++++++++++++--------------- ui/styling/style.ts | 10 +++++- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/ui/core/dependency-observable.d.ts b/ui/core/dependency-observable.d.ts index 209dd9908..5b265bd54 100644 --- a/ui/core/dependency-observable.d.ts +++ b/ui/core/dependency-observable.d.ts @@ -73,6 +73,10 @@ declare module "ui/core/dependency-observable" { * Gets or sets the callback to be raised whenever the associated property is about to change for any DependencyObservable instance that uses the property to store a value. */ onValidateValue: PropertyValidationCallback; + /** + * Gets function that used to compare if two property values are equal. + */ + equalityComparer: PropertyEqualityComparer; /** * Checks whether the PropertyMetadataSettings.affectsLayout bit is present in the options value. */ diff --git a/ui/styling/font.ios.ts b/ui/styling/font.ios.ts index e76683671..022ba4648 100644 --- a/ui/styling/font.ios.ts +++ b/ui/styling/font.ios.ts @@ -1,32 +1,11 @@ import enums = require("ui/enums"); import common = require("ui/styling/font-common"); -import fs = require("file-system"); +import fs = require("file-system"); var DEFAULT_SERIF = "Times New Roman"; var DEFAULT_SANS_SERIF = "Helvetica"; var DEFAULT_MONOSPACE = "Courier New"; -var areSystemFontSetsValid: boolean = false; -var systemFontFamilies = new Set(); -var systemFonts = new Set(); - -function assureSystemFotnSets() { - if (!areSystemFontSetsValid) { - var nsFontFamilies = UIFont.familyNames(); - for (var i = 0; i < nsFontFamilies.count; i++) { - var family = nsFontFamilies.objectAtIndex(i); - systemFontFamilies.add(family); - - var nsFonts = UIFont.fontNamesForFamilyName(family); - for (var j = 0; j < nsFonts.count; j++) { - var font = nsFonts.objectAtIndex(j); - systemFonts.add(font); - } - } - areSystemFontSetsValid = true; - } -} - export class Font extends common.Font { public static default = new Font(undefined, undefined, enums.FontStyle.normal, enums.FontWeight.normal); @@ -48,9 +27,8 @@ export class Font extends common.Font { var descriptor = resolveFontDescriptor(this.fontFamily, symbolicTraits); if (!descriptor) { - descriptor = UIFontDescriptor.new().fontDescriptorWithSymbolicTraits(symbolicTraits); + descriptor = defaultFont.fontDescriptor().fontDescriptorWithSymbolicTraits(symbolicTraits); } - var size = this.fontSize || defaultFont.pointSize; this._uiFont = UIFont.fontWithDescriptorSize(descriptor, size); @@ -75,6 +53,27 @@ export class Font extends common.Font { } } +var areSystemFontSetsValid: boolean = false; +var systemFontFamilies = new Set(); +var systemFonts = new Set(); + +function assureSystemFontSets() { + if (!areSystemFontSetsValid) { + var nsFontFamilies = UIFont.familyNames(); + for (var i = 0; i < nsFontFamilies.count; i++) { + var family = nsFontFamilies.objectAtIndex(i); + systemFontFamilies.add(family); + + var nsFonts = UIFont.fontNamesForFamilyName(family); + for (var j = 0; j < nsFonts.count; j++) { + var font = nsFonts.objectAtIndex(j); + systemFonts.add(font); + } + } + areSystemFontSetsValid = true; + } +} + function resolveFontDescriptor(fontFamilyValue: string, symbolicTraits: number): UIFontDescriptor { var fonts = common.parseFontFamily(fontFamilyValue); var result: UIFontDescriptor = null; @@ -82,7 +81,7 @@ function resolveFontDescriptor(fontFamilyValue: string, symbolicTraits: number): return null; } - assureSystemFotnSets(); + assureSystemFontSets(); for (var i = 0; i < fonts.length; i++) { var fontFamily = getFontFamilyRespectingGenericFonts(fonts[i]); diff --git a/ui/styling/style.ts b/ui/styling/style.ts index ce20a42c8..8116da3a5 100644 --- a/ui/styling/style.ts +++ b/ui/styling/style.ts @@ -318,7 +318,15 @@ export class Style extends observable.DependencyObservable implements styling.St else { trace.write("Found handler for property: " + property.name + ", view:" + this._view, trace.categories.Style); - if (types.isUndefined(newValue) || newValue === property.metadata.defaultValue) { + var shouldReset = false; + if (property.metadata.equalityComparer) { + shouldReset = property.metadata.equalityComparer(newValue, property.metadata.defaultValue); + } + else { + shouldReset = (newValue === property.metadata.defaultValue); + } + + if (shouldReset) { (handler).resetProperty(property, this._view); } else { (handler).applyProperty(property, this._view, newValue);