mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #3266 from NativeScript/issue-3210
Fix: SegmentedBar crash using a number as title
This commit is contained in:
@@ -270,3 +270,14 @@ export var testSelectedIndexChangedIsRaisedCorrectlyIfItemsNotBound = function (
|
|||||||
TKUnit.assertEqual(newSelectedIndex, 1);
|
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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ export class SegmentedBarItem extends bindable.Bindable implements definition.Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
set title(value: string) {
|
set title(value: string) {
|
||||||
if (this._title !== value) {
|
let strValue = (value !== null && value !== undefined) ? value.toString() : "";
|
||||||
this._title = value;
|
if (this._title !== strValue) {
|
||||||
|
this._title = strValue;
|
||||||
this._update();
|
this._update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export class SegmentedBarItem extends common.SegmentedBarItem {
|
|||||||
var tabIndex = this._parent.items.indexOf(this);
|
var tabIndex = this._parent.items.indexOf(this);
|
||||||
var titleTextViewId = 16908310; // http://developer.android.com/reference/android/R.id.html#title
|
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);
|
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;
|
tabItem._parent = this;
|
||||||
|
|
||||||
var tab = this.android.newTabSpec(this.getValidIndex(index) + "");
|
var tab = this.android.newTabSpec(this.getValidIndex(index) + "");
|
||||||
tab.setIndicator(tabItem.title || "");
|
tab.setIndicator(tabItem.title + "");
|
||||||
let that = this;
|
let that = this;
|
||||||
tab.setContent(new android.widget.TabHost.TabContentFactory({
|
tab.setContent(new android.widget.TabHost.TabContentFactory({
|
||||||
createTabContent: function (tag: string): android.view.View {
|
createTabContent: function (tag: string): android.view.View {
|
||||||
|
|||||||
Reference in New Issue
Block a user