From 97d878c1070005d17b96883991a08ec8a0e35938 Mon Sep 17 00:00:00 2001 From: Alexander Djenkov Date: Wed, 6 Feb 2019 20:19:30 +0200 Subject: [PATCH] refactor(stack-layout-ios): add warning when measuring unsized scrollable child (#6784) * refactor(stack-layout-ios): add warning when measuring unsized scrollable child * fix typo --- .../layouts/stack-layout/stack-layout.ios.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tns-core-modules/ui/layouts/stack-layout/stack-layout.ios.ts b/tns-core-modules/ui/layouts/stack-layout/stack-layout.ios.ts index 62804aa91..6f3b1ca36 100644 --- a/tns-core-modules/ui/layouts/stack-layout/stack-layout.ios.ts +++ b/tns-core-modules/ui/layouts/stack-layout/stack-layout.ios.ts @@ -1,4 +1,5 @@ import { StackLayoutBase, View, layout, VerticalAlignment, HorizontalAlignment } from "./stack-layout-common"; +import * as trace from "../../../trace"; export * from "./stack-layout-common"; @@ -51,7 +52,16 @@ export class StackLayout extends StackLayoutBase { this.eachLayoutChild((child, last) => { if (isVertical) { + + // Measuring ListView, with no height property set, with layout.AT_MOST will + // result in total height equal to the count ot all items multiplied by DEFAULT_HEIGHT = 44 or the + // maximum available space for the StackLayout. Any following controls will be visible only if enough space left. childSize = View.measureChild(this, child, childMeasureSpec, layout.makeMeasureSpec(remainingLength, measureSpec)); + + if (measureSpec === layout.AT_MOST && this.isUnsizedScrollableView(child)) { + trace.write("Avoid using ListView or ScrollView with no explicit height set inside StackLayout. Doing so might result in poor user interface performance and poor user experience.", trace.categories.Layout, trace.messageType.warn); + } + measureWidth = Math.max(measureWidth, childSize.measuredWidth); let viewHeight = childSize.measuredHeight; measureHeight += viewHeight; @@ -93,7 +103,7 @@ export class StackLayout extends StackLayoutBase { } } - private layoutVertical(left: number, top: number, right: number, bottom: number, insets: {left, top, right, bottom}): void { + private layoutVertical(left: number, top: number, right: number, bottom: number, insets: { left, top, right, bottom }): void { const paddingLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left; const paddingTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top; const paddingRight = this.effectiveBorderRightWidth + this.effectivePaddingRight + insets.right; @@ -127,7 +137,7 @@ export class StackLayout extends StackLayoutBase { }) } - private layoutHorizontal(left: number, top: number, right: number, bottom: number, insets: {left, top, right, bottom}): void { + private layoutHorizontal(left: number, top: number, right: number, bottom: number, insets: { left, top, right, bottom }): void { const paddingLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left; const paddingTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top; const paddingRight = this.effectiveBorderRightWidth + this.effectivePaddingRight + insets.right; @@ -160,4 +170,12 @@ export class StackLayout extends StackLayoutBase { childLeft += childWidth; }); } + + private isUnsizedScrollableView(child: View): boolean { + if (child.height === "auto" && (child.ios instanceof UITableView || child.ios instanceof UIScrollView)) { + return true; + } + + return false; + } } \ No newline at end of file