| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ import { isIOS, isAndroid } from "tns-core-modules/platform"; | |||
| 20 | 20 | import { Label } from "tns-core-modules/ui/label"; | |
| 21 | 21 | import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base"; | |
| 22 | 22 | import * as helper from "../helper"; | |
| 23 | + import { Span, FormattedString } from "tns-core-modules/text/formatted-string"; | ||
| 23 | 24 | ||
| 24 | 25 | export class LabelTest extends testModule.UITest<LabelModule.Label> { | |
| 25 | 26 | ||
@@ -137,6 +138,102 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> { | |||
| 137 | 138 | TKUnit.assertEqual(actualNative, expectedValue); | |
| 138 | 139 | } | |
| 139 | 140 | ||
| 141 | + public test_label_shrinks_on_text_change() { | ||
| 142 | + const label = this.testView; | ||
| 143 | + label.horizontalAlignment = "left"; | ||
| 144 | + this.waitUntilTestElementIsLoaded(); | ||
| 145 | + | ||
| 146 | + label.text = "long label long label"; | ||
| 147 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 148 | + const longLabelWidth = label.getActualSize().width; | ||
| 149 | + | ||
| 150 | + label.text = "short label"; | ||
| 151 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 152 | + const shortLabelWidth = label.getActualSize().width; | ||
| 153 | + | ||
| 154 | + TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should shrink on text change."); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public test_label_shrinks_on_formatted_text_change() { | ||
| 158 | + const label = this.testView; | ||
| 159 | + label.horizontalAlignment = "left"; | ||
| 160 | + this.waitUntilTestElementIsLoaded(); | ||
| 161 | + | ||
| 162 | + const span = new Span(); | ||
| 163 | + span.text = "long label"; | ||
| 164 | + span.fontWeight = "bold"; | ||
| 165 | + | ||
| 166 | + const span2 = new Span(); | ||
| 167 | + span2.text = "long label"; | ||
| 168 | + | ||
| 169 | + const formattedString = new FormattedString(); | ||
| 170 | + formattedString.spans.push(span); | ||
| 171 | + formattedString.spans.push(span2); | ||
| 172 | + label.formattedText = formattedString; | ||
| 173 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 174 | + const longLabelWidth = label.getActualSize().width; | ||
| 175 | + | ||
| 176 | + const span3 = new Span(); | ||
| 177 | + span3.text = "short label"; | ||
| 178 | + span3.fontWeight = "bold"; | ||
| 179 | + | ||
| 180 | + const formattedString2 = new FormattedString(); | ||
| 181 | + formattedString2.spans.push(span3); | ||
| 182 | + label.formattedText = formattedString2; | ||
| 183 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 184 | + const shortLabelWidth = label.getActualSize().width; | ||
| 185 | + | ||
| 186 | + TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should shrink on formatted text change."); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + public test_label_grows_on_text_change() { | ||
| 190 | + const label = this.testView; | ||
| 191 | + label.horizontalAlignment = "left"; | ||
| 192 | + this.waitUntilTestElementIsLoaded(); | ||
| 193 | + | ||
| 194 | + label.text = "short label"; | ||
| 195 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 196 | + const shortLabelWidth = label.getActualSize().width; | ||
| 197 | + | ||
| 198 | + label.text = "long label long label"; | ||
| 199 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 200 | + const longLabelWidth = label.getActualSize().width; | ||
| 201 | + | ||
| 202 | + TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should grow on text change."); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + public test_label_grows_on_formatted_text_change() { | ||
| 206 | + const label = this.testView; | ||
| 207 | + label.horizontalAlignment = "left"; | ||
| 208 | + this.waitUntilTestElementIsLoaded(); | ||
| 209 | + | ||
| 210 | + const span = new Span(); | ||
| 211 | + span.text = "short label"; | ||
| 212 | + span.fontWeight = "bold"; | ||
| 213 | + | ||
| 214 | + const formattedString = new FormattedString(); | ||
| 215 | + formattedString.spans.push(span); | ||
| 216 | + label.formattedText = formattedString; | ||
| 217 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 218 | + const shortLabelWidth = label.getActualSize().width; | ||
| 219 | + | ||
| 220 | + const span2 = new Span(); | ||
| 221 | + span2.text = "long label"; | ||
| 222 | + span2.fontWeight = "bold"; | ||
| 223 | + | ||
| 224 | + const span3 = new Span(); | ||
| 225 | + span3.text = "long label"; | ||
| 226 | + | ||
| 227 | + const formattedString2 = new FormattedString(); | ||
| 228 | + formattedString2.spans.push(span2); | ||
| 229 | + formattedString2.spans.push(span3); | ||
| 230 | + label.formattedText = formattedString2; | ||
| 231 | + this.waitUntilTestElementLayoutIsValid(); | ||
| 232 | + const longLabelWidth = label.getActualSize().width; | ||
| 233 | + | ||
| 234 | + TKUnit.assert(longLabelWidth > shortLabelWidth, "label width should grow on formatted text change."); | ||
| 235 | + } | ||
| 236 | + | ||
| 140 | 237 | public test_measuredWidth_is_not_clipped() { | |
| 141 | 238 | const label = this.testView; | |
| 142 | 239 | label.horizontalAlignment = "left"; | |
@@ -539,7 +636,7 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> { | |||
| 539 | 636 | if (expectRequestLayout) { | |
| 540 | 637 | TKUnit.assertTrue(called, "label.requestLayout should be called."); | |
| 541 | 638 | } else { | |
| 542 | - TKUnit.assertFalse(called, "image.requestLayout should not be called."); | ||
| 639 | + TKUnit.assertFalse(called, "label.requestLayout should not be called."); | ||
| 543 | 640 | } | |
| 544 | 641 | } | |
| 545 | 642 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ import { FontStyle, FontWeight } from "../styling/font"; | |||
| 4 | 4 | import { PropertyChangeData } from "../../data/observable"; | |
| 5 | 5 | ||
| 6 | 6 | // Types. | |
| 7 | - import { View, ViewBase, Property, CssProperty, InheritedCssProperty, Style, isIOS, Observable, makeValidator, makeParser, Length } from "../core/view"; | ||
| 7 | + import { View, ViewBase, Property, CssProperty, InheritedCssProperty, Style, isAndroid, isIOS, Observable, makeValidator, makeParser, Length } from "../core/view"; | ||
| 8 | 8 | import { FormattedString, Span } from "../../text/formatted-string"; | |
| 9 | 9 | ||
| 10 | 10 | export { FormattedString, Span }; | |
@@ -169,10 +169,10 @@ export function isBold(fontWeight: FontWeight): boolean { | |||
| 169 | 169 | return fontWeight === "bold" || fontWeight === "700" || fontWeight === "800" || fontWeight === "900"; | |
| 170 | 170 | } | |
| 171 | 171 | ||
| 172 | - export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "" }); | ||
| 172 | + export const textProperty = new Property<TextBaseCommon, string>({ name: "text", defaultValue: "", affectsLayout: isAndroid }); | ||
| 173 | 173 | textProperty.register(TextBaseCommon); | |
| 174 | 174 | ||
| 175 | - export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: isIOS, valueChanged: onFormattedTextPropertyChanged }); | ||
| 175 | + export const formattedTextProperty = new Property<TextBaseCommon, FormattedString>({ name: "formattedText", affectsLayout: true, valueChanged: onFormattedTextPropertyChanged }); | ||
| 176 | 176 | formattedTextProperty.register(TextBaseCommon); | |
| 177 | 177 | ||
| 178 | 178 | function onFormattedTextPropertyChanged(textBase: TextBaseCommon, oldValue: FormattedString, newValue: FormattedString) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments