Added font related properties for SegmentedBar.

This commit is contained in:
Nedyalko Nikolov
2015-10-28 17:50:22 +02:00
parent 875ec3e277
commit 87f7b9a294
2 changed files with 113 additions and 4 deletions

View File

@ -497,11 +497,59 @@ export class SegmentedBarStyler implements definition.stylers.Styler {
return textView.getCurrentTextColor(); return textView.getCurrentTextColor();
} }
//Font methods
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
let tabHost = <android.widget.TabHost>view._nativeView;
let fontValue = <font.Font>newValue;
for (let tabIndex = 0; tabIndex < tabHost.getTabWidget().getTabCount(); tabIndex++) {
let tab = <android.view.ViewGroup>tabHost.getTabWidget().getChildTabViewAt(tabIndex);
let t = <android.widget.TextView>tab.getChildAt(1);
let typeface = fontValue.getAndroidTypeface();
if (typeface) {
t.setTypeface(typeface);
}
else {
t.setTypeface(nativeValue.typeface);
}
if (fontValue.fontSize) {
t.setTextSize(fontValue.fontSize);
}
else {
t.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
}
}
}
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
let tabHost = <android.widget.TabHost>view._nativeView;
for (let tabIndex = 0; tabIndex < tabHost.getTabWidget().getTabCount(); tabIndex++) {
let tab = <android.view.ViewGroup>tabHost.getTabWidget().getChildTabViewAt(tabIndex);
let t = <android.widget.TextView>tab.getChildAt(1);
t.setTypeface(nativeValue.typeface);
t.setTextSize(nativeValue.size);
}
}
private static getFontInternalProperty(view: view.View): any {
let tabHost = <android.widget.TabHost>view._nativeView;
var textView = new android.widget.TextView(tabHost.getContext());
return {
typeface: textView.getTypeface(),
size: textView.getTextSize()
};
}
public static registerHandlers() { public static registerHandlers() {
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler( style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
SegmentedBarStyler.setColorProperty, SegmentedBarStyler.setColorProperty,
SegmentedBarStyler.resetColorProperty, SegmentedBarStyler.resetColorProperty,
SegmentedBarStyler.getColorProperty), "SegmentedBar"); SegmentedBarStyler.getColorProperty), "SegmentedBar");
style.registerHandler(style.fontInternalProperty, new stylersCommon.StylePropertyChangedHandler(
SegmentedBarStyler.setFontInternalProperty,
SegmentedBarStyler.resetFontInternalProperty,
SegmentedBarStyler.getFontInternalProperty), "SegmentedBar");
} }
} }

View File

@ -374,23 +374,84 @@ export class TextViewStyler implements definition.stylers.Styler {
export class SegmentedBarStyler implements definition.stylers.Styler { export class SegmentedBarStyler implements definition.stylers.Styler {
//Text color methods //Text color methods
private static setColorProperty(view: view.View, newValue: any) { private static setColorProperty(view: view.View, newValue: any) {
var bar = <UISegmentedControl>view.ios; let bar = <UISegmentedControl>view.ios;
var attrs = NSMutableDictionary.new(); let currentAttrs = bar.titleTextAttributesForState(UIControlState.UIControlStateNormal);
let attrs;
if (currentAttrs) {
attrs = currentAttrs.mutableCopy();
}
else {
attrs = NSMutableDictionary.new();
}
attrs.setValueForKey(newValue, NSForegroundColorAttributeName); attrs.setValueForKey(newValue, NSForegroundColorAttributeName);
bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal); bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal);
} }
private static resetColorProperty(view: view.View, nativeValue: any) { private static resetColorProperty(view: view.View, nativeValue: any) {
var bar = <UISegmentedControl>view.ios; let bar = <UISegmentedControl>view.ios;
var attrs = NSMutableDictionary.new(); let currentAttrs = bar.titleTextAttributesForState(UIControlState.UIControlStateNormal);
let attrs;
if (currentAttrs) {
attrs = currentAttrs.mutableCopy();
}
else {
attrs = NSMutableDictionary.new();
}
attrs.setValueForKey(nativeValue, NSForegroundColorAttributeName); attrs.setValueForKey(nativeValue, NSForegroundColorAttributeName);
bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal); bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal);
} }
//Text fonts methods
private static setFontInternalProperty(view: view.View, newValue: any) {
let bar = <UISegmentedControl>view.ios;
let currentAttrs = bar.titleTextAttributesForState(UIControlState.UIControlStateNormal);
let attrs;
if (currentAttrs) {
attrs = currentAttrs.mutableCopy();
}
else {
attrs = NSMutableDictionary.new();
}
let newFont = (<font.Font>newValue).getUIFont(UIFont.systemFontOfSize(UIFont.labelFontSize()));
attrs.setValueForKey(newFont, NSFontAttributeName);
bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal);
}
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
let bar = <UISegmentedControl>view.ios;
let currentAttrs = bar.titleTextAttributesForState(UIControlState.UIControlStateNormal);
let attrs;
if (currentAttrs) {
attrs = currentAttrs.mutableCopy();
}
else {
attrs = NSMutableDictionary.new();
}
attrs.setValueForKey(nativeValue, NSFontAttributeName);
bar.setTitleTextAttributesForState(attrs, UIControlState.UIControlStateNormal);
}
private static getNativeFontValue(view: view.View) {
let bar = <UISegmentedControl>view.ios;
let currentAttrs = bar.titleTextAttributesForState(UIControlState.UIControlStateNormal);
let currentFont;
if (currentAttrs) {
currentFont = currentAttrs.objectForKey(NSFontAttributeName);
}
if (!currentFont) {
currentFont = UIFont.systemFontOfSize(UIFont.labelFontSize());
}
return currentFont;
}
public static registerHandlers() { public static registerHandlers() {
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler( style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
SegmentedBarStyler.setColorProperty, SegmentedBarStyler.setColorProperty,
SegmentedBarStyler.resetColorProperty), "SegmentedBar"); SegmentedBarStyler.resetColorProperty), "SegmentedBar");
style.registerHandler(style.fontInternalProperty, new stylersCommon.StylePropertyChangedHandler(
SegmentedBarStyler.setFontInternalProperty,
SegmentedBarStyler.resetFontInternalProperty,
SegmentedBarStyler.getNativeFontValue), "SegmentedBar");
} }
} }