From 9d6f6cca791f259d81d6505aefad08a654c57348 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Wed, 4 Jan 2017 14:13:33 +0200 Subject: [PATCH] Fix font on Android --- .../ui/search-bar/search-bar.android.ts | 16 +++++++++------- .../ui/segmented-bar/segmented-bar.android.ts | 17 +++++++++++------ .../ui/tab-view/tab-view.android.ts | 7 +++++-- .../ui/text-base/text-base.android.ts | 17 +++++++++-------- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/tns-core-modules/ui/search-bar/search-bar.android.ts b/tns-core-modules/ui/search-bar/search-bar.android.ts index 3ce9c4199..b6e041d75 100644 --- a/tns-core-modules/ui/search-bar/search-bar.android.ts +++ b/tns-core-modules/ui/search-bar/search-bar.android.ts @@ -138,16 +138,18 @@ export class SearchBar extends SearchBarBase { set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { let textView = this._getTextView(); - let typeface: android.graphics.Typeface; if (value instanceof Font) { - typeface = value.getAndroidTypeface(); - textView.setTextSize(value.fontSize); - } else { - typeface = value.typeface; + // Set value + textView.setTypeface(value.getAndroidTypeface()); + if (value.fontSize !== undefined){ + textView.setTextSize(value.fontSize); + } + } + else { + // Reset value + textView.setTypeface(value.typeface); textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize); } - - textView.setTypeface(typeface); } get [backgroundInternalProperty.native](): Font { diff --git a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts index 51c98c679..ff2670b3d 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts @@ -94,13 +94,18 @@ export class SegmentedBarItem extends SegmentedBarItemBase { }; } set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { - let tv = this._textView; + let textView = this._textView; if (value instanceof Font) { - tv.setTypeface(value.getAndroidTypeface()); - tv.setTextSize(value.fontSize); - } else { - tv.setTypeface(value.typeface); - tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize); + // Set value + textView.setTypeface(value.getAndroidTypeface()); + if (value.fontSize !== undefined){ + textView.setTextSize(value.fontSize); + } + } + else { + // Reset value + textView.setTypeface(value.typeface); + textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize); } } diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index 617711dce..a496117f0 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -384,7 +384,8 @@ export class TabView extends TabViewBase { if (value instanceof Font) { isFont = true; typeface = value.getAndroidTypeface(); - } else { + } + else { typeface = value.typeface; } @@ -397,7 +398,9 @@ export class TabView extends TabViewBase { tv.setTypeface(typeface); if (isFont) { - tv.setTextSize(fontSize); + if (fontSize !== undefined){ + tv.setTextSize(fontSize); + } } else { tv.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, fontSize); diff --git a/tns-core-modules/ui/text-base/text-base.android.ts b/tns-core-modules/ui/text-base/text-base.android.ts index 86be64bc4..7b6474c31 100644 --- a/tns-core-modules/ui/text-base/text-base.android.ts +++ b/tns-core-modules/ui/text-base/text-base.android.ts @@ -52,17 +52,18 @@ export class TextBase extends TextBaseCommon { } set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { let textView = this._nativeView; - - let typeface: android.graphics.Typeface; if (value instanceof Font) { - typeface = value.getAndroidTypeface(); - textView.setTextSize(value.fontSize); - } else { - typeface = value.typeface; + // Set value + textView.setTypeface(value.getAndroidTypeface()); + if (value.fontSize !== undefined){ + textView.setTextSize(value.fontSize); + } + } + else { + // Reset value + textView.setTypeface(value.typeface); textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize); } - - textView.setTypeface(typeface); } //TextAlignment