Skip to content

Commit 9eb66d8

Browse files
author
vakrilov
committed
Inherit font properties form view inside spans
1 parent 6841c66 commit 9eb66d8

6 files changed

Lines changed: 48 additions & 6 deletions

File tree

text/formatted-string-common.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ export class FormattedString extends observable.Observable implements definition
2121
private _underline: number;
2222
private _strikethrough: number;
2323
private _fontAttributes: number;
24+
private _parent: view.View;
25+
26+
get parent(): view.View {
27+
return this._parent;
28+
}
29+
30+
set parent(value: view.View) {
31+
if (this._parent !== value) {
32+
this._parent = value;
33+
}
34+
}
2435

2536
get fontFamily(): string {
2637
return this._fontFamily;

text/formatted-string.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ declare module "text/formatted-string" {
66
import observable = require("data/observable");
77
import observableArray = require("data/observable-array");
88
import colorModule = require("color");
9+
import view = require("ui/core/view");
910

1011
/**
1112
* A class used to create a formatted (rich text) string.
@@ -66,5 +67,10 @@ declare module "text/formatted-string" {
6667
* @param newBindingContext The value of the newly set binding context.
6768
*/
6869
public updateSpansBindingContext(newBindingContext: any): void
70+
71+
/**
72+
* Gets the parent view of the formatted string.
73+
*/
74+
public parent: view.View;
6975
}
7076
}

text/span.android.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@ export class Span extends spanCommon.Span {
1313
if (realFontFamily) {
1414
this.spanModifiers.push(new android.text.style.TypefaceSpan(realFontFamily));
1515
}
16-
var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined);
16+
var realFontSize = this.fontSize ||
17+
(parent ? parent.fontSize : undefined) ||
18+
(parent && parent.parent ? parent.parent.style.fontSize : undefined);
1719
if (realFontSize) {
1820
this.spanModifiers.push(new android.text.style.AbsoluteSizeSpan(realFontSize * utils.layout.getDisplayDensity()));
1921
}
20-
var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined);
22+
23+
var realForegroundColor = this.foregroundColor ||
24+
(parent ? parent.foregroundColor : undefined) ||
25+
(parent && parent.parent ? parent.parent.style.color : undefined);
2126
if (realForegroundColor) {
2227
this.spanModifiers.push(new android.text.style.ForegroundColorSpan(realForegroundColor.android));
2328
}
24-
var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined);
29+
30+
var realBackgroundColor = this.backgroundColor ||
31+
(parent ? parent.backgroundColor : undefined) ||
32+
(parent && parent.parent ? parent.parent.style.backgroundColor : undefined);
2533
if (realBackgroundColor) {
2634
this.spanModifiers.push(new android.text.style.BackgroundColorSpan(realBackgroundColor.android));
2735
}
36+
2837
var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined);
2938
if (realFontAttributes) {
3039
if ((realFontAttributes & enums.FontAttributes.Bold) && (realFontAttributes & enums.FontAttributes.Italic)) {

text/span.ios.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export class Span extends spanCommon.Span {
99
public updateSpanModifiers(parent: formattedString.FormattedString) {
1010
super.updateSpanModifiers(parent);
1111
var realFontFamily = this.fontFamily || (parent ? parent.fontFamily : undefined);
12-
var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined);
12+
var realFontSize = this.fontSize ||
13+
(parent ? parent.fontSize : undefined) ||
14+
(parent && parent.parent ? parent.parent.style.fontSize : undefined);
15+
1316
var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined);
1417
if (realFontAttributes || realFontFamily || realFontSize) {
1518
var font;
@@ -37,20 +40,27 @@ export class Span extends spanCommon.Span {
3740
});
3841
}
3942
}
40-
var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined);
43+
44+
var realForegroundColor = this.foregroundColor ||
45+
(parent ? parent.foregroundColor : undefined) ||
46+
(parent && parent.parent ? parent.parent.style.color : undefined);
4147
if (realForegroundColor) {
4248
this.spanModifiers.push({
4349
key: NSForegroundColorAttributeName,
4450
value: realForegroundColor.ios
4551
});
4652
}
47-
var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined);
53+
54+
var realBackgroundColor = this.backgroundColor ||
55+
(parent ? parent.backgroundColor : undefined) ||
56+
(parent && parent.parent ? parent.parent.style.backgroundColor : undefined);
4857
if (realBackgroundColor) {
4958
this.spanModifiers.push({
5059
key: NSBackgroundColorAttributeName,
5160
value: realBackgroundColor.ios
5261
});
5362
}
63+
5464
var realUnderline = this.underline || (parent ? parent.underline : undefined);
5565
if (realUnderline) {
5666
this.spanModifiers.push({

ui/button/button-common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ export class Button extends view.View implements definition.Button {
110110
}
111111

112112
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
113+
if (data.newValue) {
114+
(<formattedString.FormattedString>data.newValue).parent = this;
115+
}
113116
this.setFormattedTextPropertyToNative(data.newValue);
114117
}
115118
}

ui/text-base/text-base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export class TextBase extends view.View implements definition.TextBase {
104104
}
105105

106106
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
107+
if (data.newValue) {
108+
(<formattedString.FormattedString>data.newValue).parent = this;
109+
}
107110
this.setFormattedTextPropertyToNative(data.newValue);
108111
}
109112

0 commit comments

Comments
 (0)