mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 20:00:16 +08:00
fix flexbox tests
This commit is contained in:
@ -84,6 +84,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
_oldRight: number;
|
||||
_oldBottom: number;
|
||||
|
||||
_minWidthNative: Length;
|
||||
_minHeightNative: Length;
|
||||
|
||||
private _isLayoutValid: boolean;
|
||||
private _cssType: string;
|
||||
|
||||
@ -881,7 +884,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
throw new Error("The View._setValue is obsolete. There is a new property system.")
|
||||
}
|
||||
|
||||
_updateEffectiveLayoutValues(parent: ViewCommon): void {
|
||||
_updateEffectiveLayoutValues(parent: ViewDefinition): void {
|
||||
const density = layout.getDisplayDensity();
|
||||
const style = this.style;
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { PercentLength, Point, CustomLayoutView as CustomLayoutViewDefinition } from "ui/core/view";
|
||||
import { ad as androidBackground } from "ui/styling/background";
|
||||
import {
|
||||
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty, visibilityProperty, opacityProperty, minWidthProperty, minHeightProperty,
|
||||
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty, visibilityProperty, opacityProperty,
|
||||
minWidthProperty, minHeightProperty, Length,
|
||||
widthProperty, heightProperty, marginLeftProperty, marginTopProperty,
|
||||
marginRightProperty, marginBottomProperty, horizontalAlignmentProperty, verticalAlignmentProperty,
|
||||
rotateProperty, scaleXProperty, scaleYProperty,
|
||||
@ -447,6 +448,22 @@ export class View extends ViewCommon {
|
||||
androidBackground.onBackgroundOrBorderPropertyChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
set [minWidthProperty.native](value: Length) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeView) {
|
||||
this.parent._setChildMinWidthNative(this);
|
||||
} else {
|
||||
this._minWidthNative = this.minWidth;
|
||||
}
|
||||
}
|
||||
|
||||
set [minHeightProperty.native](value: Length) {
|
||||
if (this.parent instanceof CustomLayoutView && this.parent.nativeView) {
|
||||
this.parent._setChildMinHeightNative(this);
|
||||
} else {
|
||||
this._minHeightNative = this.minHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type NativeSetter = { (view: android.view.View, value: number): void };
|
||||
@ -534,13 +551,13 @@ createNativePercentLengthProperty({
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
key: minWidthProperty.native,
|
||||
key: "_minWidthNative",
|
||||
getPixels: ViewHelper.getMinWidth,
|
||||
setPixels: ViewHelper.setMinWidth
|
||||
});
|
||||
|
||||
createNativePercentLengthProperty({
|
||||
key: minHeightProperty.native,
|
||||
key: "_minHeightNative",
|
||||
getPixels: ViewHelper.getMinHeight,
|
||||
setPixels: ViewHelper.setMinHeight
|
||||
});
|
||||
@ -568,12 +585,36 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
|
||||
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
|
||||
}
|
||||
this._nativeView.addView(child.nativeView, atIndex);
|
||||
if (child instanceof View) {
|
||||
this._updateNativeLayoutParams(child);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public _setChildMinWidthNative(child: View): void {
|
||||
child._minWidthNative = child.minWidth;
|
||||
}
|
||||
|
||||
public _setChildMinHeightNative(child: View): void {
|
||||
child._minHeightNative = child.minHeight;
|
||||
}
|
||||
|
||||
public _removeViewFromNativeVisualTree(child: ViewCommon): void {
|
||||
super._removeViewFromNativeVisualTree(child);
|
||||
|
||||
|
11
tns-core-modules/ui/core/view.d.ts
vendored
11
tns-core-modules/ui/core/view.d.ts
vendored
@ -571,6 +571,12 @@ declare module "ui/core/view" {
|
||||
// _onStylePropertyChanged(property: dependencyObservable.Property): void;
|
||||
|
||||
_updateEffectiveLayoutValues(parent: View): void;
|
||||
|
||||
_currentWidthMeasureSpec: number;
|
||||
_currentHeightMeasureSpec: number;
|
||||
|
||||
_minWidthNative: Length;
|
||||
_minHeightNative: Length;
|
||||
//@endprivate
|
||||
|
||||
public effectiveMinWidth: number;
|
||||
@ -605,6 +611,11 @@ declare module "ui/core/view" {
|
||||
* Base class for all UI components that implements custom layouts.
|
||||
*/
|
||||
export class CustomLayoutView extends View {
|
||||
//@private
|
||||
_updateNativeLayoutParams(child: View): void;
|
||||
_setChildMinWidthNative(child: View): void;
|
||||
_setChildMinHeightNative(child: View): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,12 @@
|
||||
import {
|
||||
FlexDirection, FlexWrap, JustifyContent, AlignItems, AlignContent,
|
||||
FlexboxLayoutBase, View, layout,
|
||||
FlexboxLayoutBase, View, ViewBase, layout,
|
||||
widthProperty, heightProperty, minWidthProperty, minHeightProperty,
|
||||
marginTopProperty, marginRightProperty, marginBottomProperty, marginLeftProperty,
|
||||
Length,
|
||||
orderProperty, Order,
|
||||
flexGrowProperty, FlexGrow,
|
||||
flexShrinkProperty, FlexShrink,
|
||||
flexGrowProperty, FlexGrow,
|
||||
flexShrinkProperty, FlexShrink,
|
||||
flexWrapBeforeProperty, FlexWrapBefore,
|
||||
alignSelfProperty, AlignSelf,
|
||||
flexDirectionProperty, flexWrapProperty, justifyContentProperty, alignItemsProperty, alignContentProperty
|
||||
@ -173,15 +176,32 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
||||
set [alignContentProperty.native](alignContent: AlignContent) {
|
||||
this.android.setAlignContent(alignContentMap[alignContent]);
|
||||
}
|
||||
}
|
||||
|
||||
export function _setAndroidLayoutParams(lp: org.nativescript.widgets.FlexboxLayout.LayoutParams, view: View) {
|
||||
lp.order = FlexboxLayout.getOrder(view);
|
||||
lp.flexGrow = FlexboxLayout.getFlexGrow(view);
|
||||
lp.flexShrink = FlexboxLayout.getFlexShrink(view);
|
||||
lp.alignSelf = alignSelfMap[FlexboxLayout.getAlignSelf(view)];
|
||||
lp.wrapBefore = FlexboxLayout.getFlexWrapBefore(view);
|
||||
public _updateNativeLayoutParams(child: View): void {
|
||||
super._updateNativeLayoutParams(child);
|
||||
|
||||
lp.minWidth = layout.toDevicePixels(view.effectiveMinWidth);
|
||||
lp.minHeight = layout.toDevicePixels(view.effectiveMinHeight);
|
||||
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;
|
||||
}
|
||||
|
||||
public _setChildMinWidthNative(child: View): void {
|
||||
child._minWidthNative = 0;
|
||||
const lp = child.nativeView.getLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.FlexboxLayout.LayoutParams) {
|
||||
lp.minWidth = Length.toDevicePixels(child.minWidth, 0);
|
||||
child.nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
public _setChildMinHeightNative(child: View): void {
|
||||
child._minHeightNative = 0;
|
||||
const lp = child.nativeView.getLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.FlexboxLayout.LayoutParams) {
|
||||
lp.minHeight = Length.toDevicePixels(child.minHeight, 0);
|
||||
child.nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user