fix flexbox tests

This commit is contained in:
Panayot Cankov
2017-01-04 11:53:58 +02:00
parent d8db6a2484
commit 4ae6473e48
4 changed files with 91 additions and 16 deletions

View File

@ -84,6 +84,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
_oldRight: number; _oldRight: number;
_oldBottom: number; _oldBottom: number;
_minWidthNative: Length;
_minHeightNative: Length;
private _isLayoutValid: boolean; private _isLayoutValid: boolean;
private _cssType: string; 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.") 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 density = layout.getDisplayDensity();
const style = this.style; const style = this.style;

View File

@ -1,7 +1,8 @@
import { PercentLength, Point, CustomLayoutView as CustomLayoutViewDefinition } from "ui/core/view"; import { PercentLength, Point, CustomLayoutView as CustomLayoutViewDefinition } from "ui/core/view";
import { ad as androidBackground } from "ui/styling/background"; import { ad as androidBackground } from "ui/styling/background";
import { 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, widthProperty, heightProperty, marginLeftProperty, marginTopProperty,
marginRightProperty, marginBottomProperty, horizontalAlignmentProperty, verticalAlignmentProperty, marginRightProperty, marginBottomProperty, horizontalAlignmentProperty, verticalAlignmentProperty,
rotateProperty, scaleXProperty, scaleYProperty, rotateProperty, scaleXProperty, scaleYProperty,
@ -447,6 +448,22 @@ export class View extends ViewCommon {
androidBackground.onBackgroundOrBorderPropertyChanged(this); 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 }; type NativeSetter = { (view: android.view.View, value: number): void };
@ -534,13 +551,13 @@ createNativePercentLengthProperty({
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: minWidthProperty.native, key: "_minWidthNative",
getPixels: ViewHelper.getMinWidth, getPixels: ViewHelper.getMinWidth,
setPixels: ViewHelper.setMinWidth setPixels: ViewHelper.setMinWidth
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: minHeightProperty.native, key: "_minHeightNative",
getPixels: ViewHelper.getMinHeight, getPixels: ViewHelper.getMinHeight,
setPixels: ViewHelper.setMinHeight setPixels: ViewHelper.setMinHeight
}); });
@ -568,12 +585,36 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents); traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
} }
this._nativeView.addView(child.nativeView, atIndex); this._nativeView.addView(child.nativeView, atIndex);
if (child instanceof View) {
this._updateNativeLayoutParams(child);
}
return true; return true;
} }
return false; 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 { public _removeViewFromNativeVisualTree(child: ViewCommon): void {
super._removeViewFromNativeVisualTree(child); super._removeViewFromNativeVisualTree(child);

View File

@ -571,6 +571,12 @@ declare module "ui/core/view" {
// _onStylePropertyChanged(property: dependencyObservable.Property): void; // _onStylePropertyChanged(property: dependencyObservable.Property): void;
_updateEffectiveLayoutValues(parent: View): void; _updateEffectiveLayoutValues(parent: View): void;
_currentWidthMeasureSpec: number;
_currentHeightMeasureSpec: number;
_minWidthNative: Length;
_minHeightNative: Length;
//@endprivate //@endprivate
public effectiveMinWidth: number; public effectiveMinWidth: number;
@ -605,6 +611,11 @@ declare module "ui/core/view" {
* Base class for all UI components that implements custom layouts. * Base class for all UI components that implements custom layouts.
*/ */
export class CustomLayoutView extends View { export class CustomLayoutView extends View {
//@private
_updateNativeLayoutParams(child: View): void;
_setChildMinWidthNative(child: View): void;
_setChildMinHeightNative(child: View): void;
//@endprivate
} }
/** /**

View File

@ -1,6 +1,9 @@
import { import {
FlexDirection, FlexWrap, JustifyContent, AlignItems, AlignContent, FlexDirection, FlexWrap, JustifyContent, AlignItems, AlignContent,
FlexboxLayoutBase, View, layout, FlexboxLayoutBase, View, ViewBase, layout,
widthProperty, heightProperty, minWidthProperty, minHeightProperty,
marginTopProperty, marginRightProperty, marginBottomProperty, marginLeftProperty,
Length,
orderProperty, Order, orderProperty, Order,
flexGrowProperty, FlexGrow, flexGrowProperty, FlexGrow,
flexShrinkProperty, FlexShrink, flexShrinkProperty, FlexShrink,
@ -173,15 +176,32 @@ export class FlexboxLayout extends FlexboxLayoutBase {
set [alignContentProperty.native](alignContent: AlignContent) { set [alignContentProperty.native](alignContent: AlignContent) {
this.android.setAlignContent(alignContentMap[alignContent]); this.android.setAlignContent(alignContentMap[alignContent]);
} }
}
export function _setAndroidLayoutParams(lp: org.nativescript.widgets.FlexboxLayout.LayoutParams, view: View) { public _updateNativeLayoutParams(child: View): void {
lp.order = FlexboxLayout.getOrder(view); super._updateNativeLayoutParams(child);
lp.flexGrow = FlexboxLayout.getFlexGrow(view);
lp.flexShrink = FlexboxLayout.getFlexShrink(view);
lp.alignSelf = alignSelfMap[FlexboxLayout.getAlignSelf(view)];
lp.wrapBefore = FlexboxLayout.getFlexWrapBefore(view);
lp.minWidth = layout.toDevicePixels(view.effectiveMinWidth); child[orderProperty.native] = child.order;
lp.minHeight = layout.toDevicePixels(view.effectiveMinHeight); 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);
}
}
} }