Skip to content

Commit 8767522

Browse files
authored
Merge pull request NativeScript#3266 from NativeScript/issue-3210
Fix: SegmentedBar crash using a number as title
2 parents c5e3e81 + d05f5f6 commit 8767522

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

tests/app/ui/segmented-bar/segmented-bar-tests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,14 @@ export var testSelectedIndexChangedIsRaisedCorrectlyIfItemsNotBound = function (
270270
TKUnit.assertEqual(newSelectedIndex, 1);
271271
});
272272
}
273+
274+
export function test_SettingNumberAsTitleFromXML_DoesNotThrow() {
275+
let segmentedBar = new segmentedBarModule.SegmentedBar();
276+
let item = new segmentedBarModule.SegmentedBarItem();
277+
(<any>item).title = 1;
278+
segmentedBar.items = [item];
279+
280+
buildUIAndRunTest(segmentedBar, function (views: Array<View>) {
281+
TKUnit.assertEqual(item.title, "1");
282+
});
283+
}

tns-core-modules/ui/segmented-bar/segmented-bar-common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export class SegmentedBarItem extends bindable.Bindable implements definition.Se
2828
}
2929

3030
set title(value: string) {
31-
if (this._title !== value) {
32-
this._title = value;
31+
let strValue = (value !== null && value !== undefined) ? value.toString() : "";
32+
if (this._title !== strValue) {
33+
this._title = strValue;
3334
this._update();
3435
}
3536
}

tns-core-modules/ui/segmented-bar/segmented-bar.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class SegmentedBarItem extends common.SegmentedBarItem {
110110
var tabIndex = this._parent.items.indexOf(this);
111111
var titleTextViewId = 16908310; // http://developer.android.com/reference/android/R.id.html#title
112112
var titleTextView = <android.widget.TextView>this._parent.android.getTabWidget().getChildAt(tabIndex).findViewById(titleTextViewId);
113-
titleTextView.setText(this.title || "");
113+
titleTextView.setText(this.title + "");
114114
}
115115
}
116116
}
@@ -162,7 +162,7 @@ export class SegmentedBar extends common.SegmentedBar {
162162
tabItem._parent = this;
163163

164164
var tab = this.android.newTabSpec(this.getValidIndex(index) + "");
165-
tab.setIndicator(tabItem.title || "");
165+
tab.setIndicator(tabItem.title + "");
166166
let that = this;
167167
tab.setContent(new android.widget.TabHost.TabContentFactory({
168168
createTabContent: function (tag: string): android.view.View {

0 commit comments

Comments
 (0)