From a1c570c702bd82df3481104c4afb96d3b3986325 Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Fri, 17 Aug 2018 18:24:06 +0300 Subject: [PATCH] fix(ios): nowrap label measure in horizontal stack layout (#6186) --- apps/app/ui-tests-app/layouts/main-page.ts | 1 + .../ui-tests-app/layouts/stacklayout-6059.xml | 40 +++++++++++++++++++ tns-core-modules/ui/label/label.ios.ts | 24 ++++++++--- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 apps/app/ui-tests-app/layouts/stacklayout-6059.xml diff --git a/apps/app/ui-tests-app/layouts/main-page.ts b/apps/app/ui-tests-app/layouts/main-page.ts index 65f67df57..3111f135b 100644 --- a/apps/app/ui-tests-app/layouts/main-page.ts +++ b/apps/app/ui-tests-app/layouts/main-page.ts @@ -21,6 +21,7 @@ export function loadExamples() { examples.set("pgrid", "layouts-percent/grid"); examples.set("pstack", "layouts-percent/stack"); examples.set("pwrap", "layouts-percent/wrap"); + examples.set("stacklayout-6059", "layouts/stacklayout-6059"); return examples; } \ No newline at end of file diff --git a/apps/app/ui-tests-app/layouts/stacklayout-6059.xml b/apps/app/ui-tests-app/layouts/stacklayout-6059.xml new file mode 100644 index 000000000..df411af66 --- /dev/null +++ b/apps/app/ui-tests-app/layouts/stacklayout-6059.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tns-core-modules/ui/label/label.ios.ts b/tns-core-modules/ui/label/label.ios.ts index e35c13297..555e29a8b 100644 --- a/tns-core-modules/ui/label/label.ios.ts +++ b/tns-core-modules/ui/label/label.ios.ts @@ -68,11 +68,25 @@ export class Label extends TextBase implements LabelDefinition { this._fixedSize = (widthMode === layout.EXACTLY ? FixedSize.WIDTH : FixedSize.NONE) | (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE); - // NOTE: utils.measureNativeView(...) relies on UIView.sizeThatFits(...) that - // seems to have various issues when laying out UILabel instances. - // We use custom measure logic here that relies on overriden - // UILabel.textRectForBounds:limitedToNumberOfLines: in TNSLabel widget. - const nativeSize = this._measureNativeView(width, widthMode, height, heightMode); + let nativeSize; + if (this.textWrap) { + // https://github.com/NativeScript/NativeScript/issues/4834 + // NOTE: utils.measureNativeView(...) relies on UIView.sizeThatFits(...) that + // seems to have various issues when laying out UILabel instances. + // We use custom measure logic here that relies on overriden + // UILabel.textRectForBounds:limitedToNumberOfLines: in TNSLabel widget. + nativeSize = this._measureNativeView(width, widthMode, height, heightMode); + } else { + // https://github.com/NativeScript/NativeScript/issues/6059 + // NOTE: _measureNativeView override breaks a scenario with StackLayout that arranges + // labels horizontally (with textWrap=false) e.g. we are measuring label #2 within 356px, + // label #2 needs more, and decides to show ellipsis(...) but because of this its native size + // returned from UILabel.textRectForBounds:limitedToNumberOfLines: logic becomes 344px, so + // StackLayout tries to measure label #3 within the remaining 12px which is wrong; + // label #2 with ellipsis should take the whole 356px and label #3 should not be visible at all. + nativeSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode); + } + let labelWidth = nativeSize.width; if (this.textWrap && widthMode === layout.AT_MOST) {