diff --git a/text/formatted-string-common.ts b/text/formatted-string-common.ts index 76a71d618..c57ecf861 100644 --- a/text/formatted-string-common.ts +++ b/text/formatted-string-common.ts @@ -21,6 +21,17 @@ export class FormattedString extends observable.Observable implements definition private _underline: number; private _strikethrough: number; private _fontAttributes: number; + private _parent: view.View; + + get parent(): view.View { + return this._parent; + } + + set parent(value: view.View) { + if (this._parent !== value) { + this._parent = value; + } + } get fontFamily(): string { return this._fontFamily; diff --git a/text/formatted-string.d.ts b/text/formatted-string.d.ts index c43536a03..19b7ef2cd 100644 --- a/text/formatted-string.d.ts +++ b/text/formatted-string.d.ts @@ -6,6 +6,7 @@ declare module "text/formatted-string" { import observable = require("data/observable"); import observableArray = require("data/observable-array"); import colorModule = require("color"); + import view = require("ui/core/view"); /** * A class used to create a formatted (rich text) string. @@ -66,5 +67,10 @@ declare module "text/formatted-string" { * @param newBindingContext The value of the newly set binding context. */ public updateSpansBindingContext(newBindingContext: any): void + + /** + * Gets the parent view of the formatted string. + */ + public parent: view.View; } } \ No newline at end of file diff --git a/text/span.android.ts b/text/span.android.ts index 3498b7f72..02d2fc870 100644 --- a/text/span.android.ts +++ b/text/span.android.ts @@ -13,18 +13,27 @@ export class Span extends spanCommon.Span { if (realFontFamily) { this.spanModifiers.push(new android.text.style.TypefaceSpan(realFontFamily)); } - var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined); + var realFontSize = this.fontSize || + (parent ? parent.fontSize : undefined) || + (parent && parent.parent ? parent.parent.style.fontSize : undefined); if (realFontSize) { this.spanModifiers.push(new android.text.style.AbsoluteSizeSpan(realFontSize * utils.layout.getDisplayDensity())); } - var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined); + + var realForegroundColor = this.foregroundColor || + (parent ? parent.foregroundColor : undefined) || + (parent && parent.parent ? parent.parent.style.color : undefined); if (realForegroundColor) { this.spanModifiers.push(new android.text.style.ForegroundColorSpan(realForegroundColor.android)); } - var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined); + + var realBackgroundColor = this.backgroundColor || + (parent ? parent.backgroundColor : undefined) || + (parent && parent.parent ? parent.parent.style.backgroundColor : undefined); if (realBackgroundColor) { this.spanModifiers.push(new android.text.style.BackgroundColorSpan(realBackgroundColor.android)); } + var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined); if (realFontAttributes) { if ((realFontAttributes & enums.FontAttributes.Bold) && (realFontAttributes & enums.FontAttributes.Italic)) { diff --git a/text/span.ios.ts b/text/span.ios.ts index 867b67066..70935fb90 100644 --- a/text/span.ios.ts +++ b/text/span.ios.ts @@ -9,7 +9,10 @@ export class Span extends spanCommon.Span { public updateSpanModifiers(parent: formattedString.FormattedString) { super.updateSpanModifiers(parent); var realFontFamily = this.fontFamily || (parent ? parent.fontFamily : undefined); - var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined); + var realFontSize = this.fontSize || + (parent ? parent.fontSize : undefined) || + (parent && parent.parent ? parent.parent.style.fontSize : undefined); + var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined); if (realFontAttributes || realFontFamily || realFontSize) { var font; @@ -37,20 +40,27 @@ export class Span extends spanCommon.Span { }); } } - var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined); + + var realForegroundColor = this.foregroundColor || + (parent ? parent.foregroundColor : undefined) || + (parent && parent.parent ? parent.parent.style.color : undefined); if (realForegroundColor) { this.spanModifiers.push({ key: NSForegroundColorAttributeName, value: realForegroundColor.ios }); } - var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined); + + var realBackgroundColor = this.backgroundColor || + (parent ? parent.backgroundColor : undefined) || + (parent && parent.parent ? parent.parent.style.backgroundColor : undefined); if (realBackgroundColor) { this.spanModifiers.push({ key: NSBackgroundColorAttributeName, value: realBackgroundColor.ios }); } + var realUnderline = this.underline || (parent ? parent.underline : undefined); if (realUnderline) { this.spanModifiers.push({ diff --git a/ui/button/button-common.ts b/ui/button/button-common.ts index e07caa612..4c4cf291d 100644 --- a/ui/button/button-common.ts +++ b/ui/button/button-common.ts @@ -110,6 +110,9 @@ export class Button extends view.View implements definition.Button { } public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) { + if (data.newValue) { + (data.newValue).parent = this; + } this.setFormattedTextPropertyToNative(data.newValue); } } \ No newline at end of file diff --git a/ui/text-base/text-base.ts b/ui/text-base/text-base.ts index 95d1c224e..3a0cb322a 100644 --- a/ui/text-base/text-base.ts +++ b/ui/text-base/text-base.ts @@ -104,6 +104,9 @@ export class TextBase extends view.View implements definition.TextBase { } public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) { + if (data.newValue) { + (data.newValue).parent = this; + } this.setFormattedTextPropertyToNative(data.newValue); }