FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(android): label width shrinking on shorter text change by manoldonev · Pull Request #5917 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
99 changes: 98 additions & 1 deletion tests/app/ui/label/label-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { isIOS, isAndroid } from "tns-core-modules/platform";
import { Label } from "tns-core-modules/ui/label";
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
import * as helper from "../helper";
import { Span, FormattedString } from "tns-core-modules/text/formatted-string";

export class LabelTest extends testModule.UITest<LabelModule.Label> {

Expand Down Expand Up @@ -137,6 +138,102 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
TKUnit.assertEqual(actualNative, expectedValue);
}

public test_label_shrinks_on_text_change() {
const label = this.testView;
label.horizontalAlignment = "left";
this.waitUntilTestElementIsLoaded();

label.text = "long label long label";
this.waitUntilTestElementLayoutIsValid();
const longLabelWidth = label.getActualSize().width;

label.text = "short label";
this.waitUntilTestElementLayoutIsValid();
const shortLabelWidth = label.getActualSize().width;

TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should shrink on text change.");
}

public test_label_shrinks_on_formatted_text_change() {
const label = this.testView;
label.horizontalAlignment = "left";
this.waitUntilTestElementIsLoaded();

const span = new Span();
span.text = "long label";
span.fontWeight = "bold";

const span2 = new Span();
span2.text = "long label";

const formattedString = new FormattedString();
formattedString.spans.push(span);
formattedString.spans.push(span2);
label.formattedText = formattedString;
this.waitUntilTestElementLayoutIsValid();
const longLabelWidth = label.getActualSize().width;

const span3 = new Span();
span3.text = "short label";
span3.fontWeight = "bold";

const formattedString2 = new FormattedString();
formattedString2.spans.push(span3);
label.formattedText = formattedString2;
this.waitUntilTestElementLayoutIsValid();
const shortLabelWidth = label.getActualSize().width;

TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should shrink on formatted text change.");
}

public test_label_grows_on_text_change() {
const label = this.testView;
label.horizontalAlignment = "left";
this.waitUntilTestElementIsLoaded();

label.text = "short label";
this.waitUntilTestElementLayoutIsValid();
const shortLabelWidth = label.getActualSize().width;

label.text = "long label long label";
this.waitUntilTestElementLayoutIsValid();
const longLabelWidth = label.getActualSize().width;

TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should grow on text change.");
}

public test_label_grows_on_formatted_text_change() {
const label = this.testView;
label.horizontalAlignment = "left";
this.waitUntilTestElementIsLoaded();

const span = new Span();
span.text = "short label";
span.fontWeight = "bold";

const formattedString = new FormattedString();
formattedString.spans.push(span);
label.formattedText = formattedString;
this.waitUntilTestElementLayoutIsValid();
const shortLabelWidth = label.getActualSize().width;

const span2 = new Span();
span2.text = "long label";
span2.fontWeight = "bold";

const span3 = new Span();
span3.text = "long label";

const formattedString2 = new FormattedString();
formattedString2.spans.push(span2);
formattedString2.spans.push(span3);
label.formattedText = formattedString2;
this.waitUntilTestElementLayoutIsValid();
const longLabelWidth = label.getActualSize().width;

TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should grow on formatted text change.");
}

public test_measuredWidth_is_not_clipped() {
const label = this.testView;
label.horizontalAlignment = "left";
Expand Down Expand Up @@ -539,7 +636,7 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
if (expectRequestLayout) {
TKUnit.assertTrue(called, "label.requestLayout should be called.");
} else {
TKUnit.assertFalse(called, "image.requestLayout should not be called.");
TKUnit.assertFalse(called, "label.requestLayout should not be called.");
}
}

Expand Down
6 changes: 3 additions & 3 deletions tns-core-modules/ui/text-base/text-base-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FontStyle, FontWeight } from "../styling/font";
import { PropertyChangeData } from "../../data/observable";

// Types.
import { View, ViewBase, Property, CssProperty, InheritedCssProperty, Style, isIOS, Observable, makeValidator, makeParser, Length } from "../core/view";
import { View, ViewBase, Property, CssProperty, InheritedCssProperty, Style, isAndroid, isIOS, Observable, makeValidator, makeParser, Length } from "../core/view";
import { FormattedString, Span } from "../../text/formatted-string";

export { FormattedString, Span };
Expand Down Expand Up @@ -169,10 +169,10 @@ export function isBold(fontWeight: FontWeight): boolean {
return fontWeight === "bold" || fontWeight === "700" || fontWeight === "800" || fontWeight === "900";
}

export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "" });
export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "", affectsLayout: isAndroid });
textProperty.register(TextBaseCommon);

export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: isIOS, valueChanged: onFormattedTextPropertyChanged });
export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: true, valueChanged: onFormattedTextPropertyChanged });
formattedTextProperty.register(TextBaseCommon);

function onFormattedTextPropertyChanged(textBase: TextBaseCommon, oldValue: FormattedString, newValue: FormattedString) {
Expand Down

Back | FazBrowse Home | New Git URL