From 299cac42bfa99502be423c1d5bfc8c48fa14e42d Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Thu, 8 Dec 2016 13:13:28 +0200 Subject: [PATCH] Fix: SegmentedBar crash using a number as title Resolves #issue-3210 --- tests/app/ui/segmented-bar/segmented-bar-tests.ts | 11 +++++++++++ .../ui/segmented-bar/segmented-bar-common.ts | 5 +++-- .../ui/segmented-bar/segmented-bar.android.ts | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/app/ui/segmented-bar/segmented-bar-tests.ts b/tests/app/ui/segmented-bar/segmented-bar-tests.ts index 1fbfa72c1..e81f6b14f 100644 --- a/tests/app/ui/segmented-bar/segmented-bar-tests.ts +++ b/tests/app/ui/segmented-bar/segmented-bar-tests.ts @@ -270,3 +270,14 @@ export var testSelectedIndexChangedIsRaisedCorrectlyIfItemsNotBound = function ( TKUnit.assertEqual(newSelectedIndex, 1); }); } + +export function test_SettingNumberAsTitleFromXML_DoesNotThrow() { + let segmentedBar = new segmentedBarModule.SegmentedBar(); + let item = new segmentedBarModule.SegmentedBarItem(); + (item).title = 1; + segmentedBar.items = [item]; + + buildUIAndRunTest(segmentedBar, function (views: Array) { + TKUnit.assertEqual(item.title, "1"); + }); +} diff --git a/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts b/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts index 95c599c61..9452b2b91 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts @@ -17,8 +17,9 @@ export abstract class SegmentedBarItemBase extends ViewBase implements Segmented return this._title; } set title(value: string) { - if (this._title !== value) { - this._title = value; + let strValue = (value !== null && value !== undefined) ? value.toString() : ""; + if (this._title !== strValue) { + this._title = strValue; this._update(); } } 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 8814d1cfa..51c98c679 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts @@ -211,7 +211,7 @@ export class SegmentedBar extends SegmentedBarBase { private insertTab(tabItem: SegmentedBarItem, index: number): void { const tab = this.android.newTabSpec(index + ""); - tab.setIndicator(tabItem.title); + tab.setIndicator(tabItem.title + ""); tab.setContent(this.tabContentFactory); let tabHost = this.android;