From 9bf411b7f6d72b1c6713517ca67ecdd909eb3fa0 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Wed, 4 Jan 2017 16:51:06 +0200 Subject: [PATCH] Update _updateNativeLayoutParams and fix minWidth/Height for ios flexbox --- tns-core-modules/ui/core/view.android.ts | 8 -------- .../layouts/flexbox-layout/flexbox-layout.android.ts | 12 +++++++----- .../ui/layouts/flexbox-layout/flexbox-layout.ios.ts | 8 ++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tns-core-modules/ui/core/view.android.ts b/tns-core-modules/ui/core/view.android.ts index 9e648cb43..5db5c08af 100644 --- a/tns-core-modules/ui/core/view.android.ts +++ b/tns-core-modules/ui/core/view.android.ts @@ -595,14 +595,6 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition } public _updateNativeLayoutParams(child: View): void { - child[marginTopProperty.native] = child.marginTop; - child[marginRightProperty.native] = child.marginRight; - child[marginBottomProperty.native] = child.marginBottom; - child[marginLeftProperty.native] = child.marginLeft; - - child[widthProperty.native] = child.width; - child[heightProperty.native] = child.height; - this._setChildMinWidthNative(child); this._setChildMinHeightNative(child); } diff --git a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts index 9b1cad0ef..b2c4d3e60 100644 --- a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts +++ b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.android.ts @@ -180,11 +180,13 @@ export class FlexboxLayout extends FlexboxLayoutBase { public _updateNativeLayoutParams(child: View): void { super._updateNativeLayoutParams(child); - child[orderProperty.native] = child.order; - child[flexGrowProperty.native] = child.flexGrow; - child[flexShrinkProperty.native] = child.flexShrink; - child[flexWrapBeforeProperty.native] = child.flexWrapBefore; - child[alignSelfProperty.native] = child.alignSelf; + const lp = child.nativeView.getLayoutParams(); + lp.order = child.order; + lp.flexGrow = child.flexGrow; + lp.flexShrink = child.flexShrink; + lp.wrapBefore = child.flexWrapBefore; + lp.alignSelf = alignSelfMap[child.alignSelf]; + child.nativeView.setLayoutParams(lp); } public _setChildMinWidthNative(child: View): void { diff --git a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.ios.ts b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.ios.ts index 6a05070ef..6304296bc 100644 --- a/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.ios.ts +++ b/tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout.ios.ts @@ -444,6 +444,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { let childHeight = view.getMeasuredHeight(); let minWidth = view.effectiveMinWidth; + view.effectiveMinWidth = 0; if (view.getMeasuredWidth() < minWidth) { needsMeasure = true; childWidth = minWidth; @@ -453,6 +454,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { } let minHeight = view.effectiveMinHeight; + view.effectiveMinHeight = 0; if (childHeight < minHeight) { needsMeasure = true; childHeight = minHeight; @@ -463,6 +465,8 @@ export class FlexboxLayout extends FlexboxLayoutBase { if (needsMeasure) { view.measure(makeMeasureSpec(childWidth, EXACTLY), makeMeasureSpec(childHeight, EXACTLY)); } + view.effectiveMinWidth = minWidth; + view.effectiveMinHeight = minHeight; } private _addFlexLineIfLastFlexItem(childIndex: number, childCount: number, flexLine: FlexLine) { @@ -609,6 +613,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { let rawCalculatedWidth = child.getMeasuredWidth() - unitShrink * flexShrink + accumulatedRoundError; let roundedCalculatedWidth = Math.round(rawCalculatedWidth); let minWidth = child.effectiveMinWidth; + child.effectiveMinWidth = 0; if (roundedCalculatedWidth < minWidth) { needsReshrink = true; roundedCalculatedWidth = minWidth; @@ -618,6 +623,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { accumulatedRoundError = rawCalculatedWidth - roundedCalculatedWidth; } child.measure(makeMeasureSpec(roundedCalculatedWidth, EXACTLY), makeMeasureSpec(child.getMeasuredHeight(), EXACTLY)); + child.effectiveMinWidth = minWidth; } flexLine._mainSize += child.getMeasuredWidth() + lp.effectiveMarginLeft + lp.effectiveMarginRight; } else { @@ -626,6 +632,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { let rawCalculatedHeight = child.getMeasuredHeight() - unitShrink * flexShrink + accumulatedRoundError; let roundedCalculatedHeight = Math.round(rawCalculatedHeight); const minHeight = child.effectiveMinHeight; + child.effectiveMinHeight = 0; if (roundedCalculatedHeight < minHeight) { needsReshrink = true; roundedCalculatedHeight = minHeight; @@ -635,6 +642,7 @@ export class FlexboxLayout extends FlexboxLayoutBase { accumulatedRoundError = rawCalculatedHeight - roundedCalculatedHeight; } child.measure(makeMeasureSpec(child.getMeasuredWidth(), EXACTLY), makeMeasureSpec(roundedCalculatedHeight, EXACTLY)); + child.effectiveMinHeight = minHeight; } flexLine._mainSize += child.getMeasuredHeight() + lp.effectiveMarginTop + lp.effectiveMarginBottom; }