Merge pull request #3266 from NativeScript/issue-3210

Fix: SegmentedBar crash using a number as title
This commit is contained in:
Rossen Hristov
2017-01-03 10:24:34 +02:00
committed by GitHub
3 changed files with 16 additions and 4 deletions

View File

@@ -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();
(<any>item).title = 1;
segmentedBar.items = [item];
buildUIAndRunTest(segmentedBar, function (views: Array<View>) {
TKUnit.assertEqual(item.title, "1");
});
}

View File

@@ -28,8 +28,9 @@ export class SegmentedBarItem extends bindable.Bindable implements definition.Se
}
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();
}
}

View File

@@ -110,7 +110,7 @@ export class SegmentedBarItem extends common.SegmentedBarItem {
var tabIndex = this._parent.items.indexOf(this);
var titleTextViewId = 16908310; // http://developer.android.com/reference/android/R.id.html#title
var titleTextView = <android.widget.TextView>this._parent.android.getTabWidget().getChildAt(tabIndex).findViewById(titleTextViewId);
titleTextView.setText(this.title || "");
titleTextView.setText(this.title + "");
}
}
}
@@ -162,7 +162,7 @@ export class SegmentedBar extends common.SegmentedBar {
tabItem._parent = this;
var tab = this.android.newTabSpec(this.getValidIndex(index) + "");
tab.setIndicator(tabItem.title || "");
tab.setIndicator(tabItem.title + "");
let that = this;
tab.setContent(new android.widget.TabHost.TabContentFactory({
createTabContent: function (tag: string): android.view.View {