mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Update _updateNativeLayoutParams and fix minWidth/Height for ios flexbox
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 = <org.nativescript.widgets.FlexboxLayout.LayoutParams>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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user