mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #2591 from NativeScript/nnikolov/LabelZeroHeigthIssueNew
Label zero height issue fixed.
This commit is contained in:
@ -524,12 +524,13 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
TKUnit.assertNotEqual(this.errorMessage, undefined);
|
TKUnit.assertNotEqual(this.errorMessage, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
private requestLayoutFixture(expectRequestLayout: boolean, setup: (label: Label) => LayoutBase): void {
|
private requestLayoutFixture(expectRequestLayout: boolean, initialValue: string, setup: (label: Label) => LayoutBase): void {
|
||||||
if (!isIOS) {
|
if (!isIOS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let label = new Label();
|
let label = new Label();
|
||||||
|
label.text = initialValue;
|
||||||
let host = setup(label);
|
let host = setup(label);
|
||||||
|
|
||||||
host.addChild(label);
|
host.addChild(label);
|
||||||
@ -540,7 +541,8 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
|
|
||||||
let called = false;
|
let called = false;
|
||||||
label.requestLayout = () => called = true;
|
label.requestLayout = () => called = true;
|
||||||
label.text = "Hello World";
|
// changing text actually could request layout
|
||||||
|
label.text = initialValue + " Again";
|
||||||
|
|
||||||
if (expectRequestLayout) {
|
if (expectRequestLayout) {
|
||||||
TKUnit.assertTrue(called, "label.requestLayout should be called.");
|
TKUnit.assertTrue(called, "label.requestLayout should be called.");
|
||||||
@ -550,7 +552,16 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public test_SettingTextWhenInFixedSizeGridShouldNotRequestLayout() {
|
public test_SettingTextWhenInFixedSizeGridShouldNotRequestLayout() {
|
||||||
this.requestLayoutFixture(false, () => {
|
this.requestLayoutFixture(false, "", () => {
|
||||||
|
let host = new GridLayout();
|
||||||
|
host.width = 100;
|
||||||
|
host.height = 100;
|
||||||
|
return host;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_ChangingTextWhenInFixedSizeGridShouldNotRequestLayout() {
|
||||||
|
this.requestLayoutFixture(false, "Hello World", () => {
|
||||||
let host = new GridLayout();
|
let host = new GridLayout();
|
||||||
host.width = 100;
|
host.width = 100;
|
||||||
host.height = 100;
|
host.height = 100;
|
||||||
@ -559,7 +570,16 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public test_SettingTextWhenFixedWidthAndHeightDoesNotRequestLayout() {
|
public test_SettingTextWhenFixedWidthAndHeightDoesNotRequestLayout() {
|
||||||
this.requestLayoutFixture(false, label => {
|
this.requestLayoutFixture(false, "", label => {
|
||||||
|
let host = new StackLayout();
|
||||||
|
label.width = 100;
|
||||||
|
label.height = 100;
|
||||||
|
return host;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
public test_ChangingTextWhenFixedWidthAndHeightDoesNotRequestLayout() {
|
||||||
|
this.requestLayoutFixture(false, "Hello World", label => {
|
||||||
let host = new StackLayout();
|
let host = new StackLayout();
|
||||||
label.width = 100;
|
label.width = 100;
|
||||||
label.height = 100;
|
label.height = 100;
|
||||||
@ -568,15 +588,31 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public test_SettingTextWhenSizedToContentShouldInvalidate() {
|
public test_SettingTextWhenSizedToContentShouldInvalidate() {
|
||||||
this.requestLayoutFixture(true, () => {
|
this.requestLayoutFixture(true, "", () => {
|
||||||
let host = new StackLayout();
|
let host = new StackLayout();
|
||||||
host.orientation = "horizontal";
|
host.orientation = "horizontal";
|
||||||
return host;
|
return host;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public test_SettingTextOnSingleLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldNotRequestLayout() {
|
public test_ChangingTextWhenSizedToContentShouldInvalidate() {
|
||||||
this.requestLayoutFixture(false, () => {
|
this.requestLayoutFixture(true, "Hello World", () => {
|
||||||
|
let host = new StackLayout();
|
||||||
|
host.orientation = "horizontal";
|
||||||
|
return host;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
public test_SettingTextOnSingleLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldRequestLayout() {
|
||||||
|
this.requestLayoutFixture(true, "", () => {
|
||||||
|
let host = new StackLayout();
|
||||||
|
host.width = 100;
|
||||||
|
return host;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_ChangingTextOnSingleLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldNotRequestLayout() {
|
||||||
|
this.requestLayoutFixture(false, "Hello World", () => {
|
||||||
let host = new StackLayout();
|
let host = new StackLayout();
|
||||||
host.width = 100;
|
host.width = 100;
|
||||||
return host;
|
return host;
|
||||||
@ -584,7 +620,16 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public test_SettingTextOnMultilineLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldRequestLayout() {
|
public test_SettingTextOnMultilineLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldRequestLayout() {
|
||||||
this.requestLayoutFixture(true, label => {
|
this.requestLayoutFixture(true, "", label => {
|
||||||
|
label.textWrap = true;
|
||||||
|
let host = new StackLayout();
|
||||||
|
host.width = 100;
|
||||||
|
return host;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public test_ChangingTextOnMultilineLineTextWhenWidthIsSizedToParentAndHeightIsSizedToContentShouldRequestLayout() {
|
||||||
|
this.requestLayoutFixture(true, "Hello World", label => {
|
||||||
label.textWrap = true;
|
label.textWrap = true;
|
||||||
let host = new StackLayout();
|
let host = new StackLayout();
|
||||||
host.width = 100;
|
host.width = 100;
|
||||||
|
@ -48,7 +48,7 @@ export class Label extends common.Label {
|
|||||||
if (this._fixedSize === FixedSize.BOTH) {
|
if (this._fixedSize === FixedSize.BOTH) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._fixedSize === FixedSize.WIDTH && !this.textWrap) {
|
if (this._fixedSize === FixedSize.WIDTH && !this.textWrap && this.getMeasuredHeight() > 0) {
|
||||||
// Single line label with fixed width will skip request layout on text change.
|
// Single line label with fixed width will skip request layout on text change.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user