refactor safe area application code

This commit is contained in:
Martin Yankov
2018-08-09 15:28:34 +03:00
parent 1858cba4ed
commit 8df5fbd7a8
11 changed files with 175 additions and 393 deletions

View File

@@ -156,9 +156,11 @@ export class GridLayout extends GridLayoutBase {
this.setMeasuredDimension(widthSizeAndState, heightSizeAndState);
}
public onLayout(left: number, top: number, right: number, bottom: number, insets: {left, top, right, bottom}): void {
public onLayout(left: number, top: number, right: number, bottom: number): void {
super.onLayout(left, top, right, bottom);
const insets = this.getSafeAreaInsets();
let paddingLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left;
let paddingTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top;

View File

@@ -33,82 +33,6 @@ export class LayoutBase extends LayoutBaseCommon {
}
}
public _setNativeViewFrame(nativeView: UIView, frame: CGRect) {
// if (!CGRectEqualToRect(nativeView.frame, frame)) {
// if (traceEnabled()) {
// traceWrite(this + ", Native setFrame: = " + NSStringFromCGRect(frame), traceCategories.Layout);
// }
// this._cachedFrame = frame;
// if (this._hasTransfrom) {
// // Always set identity transform before setting frame;
// const transform = nativeView.transform;
// nativeView.transform = CGAffineTransformIdentity;
// nativeView.frame = frame;
// nativeView.transform = transform;
// }
// else {
// nativeView.frame = frame;
// }
nativeView.frame = frame;
const locationOnScreen = this.getLocationInWindow();
if (locationOnScreen) {
const safeArea = this.getSafeArea();
const fullscreen = this.getFullscreenArea();
const onScreenLeft = layout.toDevicePixels(layout.round(locationOnScreen.x));
const onScreenTop = layout.toDevicePixels(layout.round(locationOnScreen.y));
let left = layout.toDevicePixels(frame.origin.x);
let top = layout.toDevicePixels(frame.origin.y);
let width = layout.toDevicePixels(frame.size.width);
let height = layout.toDevicePixels(frame.size.height);
if (majorVersion > 10) {
let newLeft = left;
let newTop = top;
let newWidth = width;
let newHeight = height;
if (left !== 0 && onScreenLeft <= layout.toDevicePixels(safeArea.origin.x)) {
newLeft = layout.toDevicePixels(fullscreen.origin.x);
newWidth = width + onScreenLeft;
}
if (top !== 0 && onScreenTop <= layout.toDevicePixels(safeArea.origin.y)) {
newTop = layout.toDevicePixels(fullscreen.origin.y);
newHeight = height + onScreenTop;
}
if (width && width < layout.toDevicePixels(fullscreen.size.width) && onScreenLeft + width >= layout.toDevicePixels(safeArea.origin.x) + layout.toDevicePixels(safeArea.size.width)) {
newWidth = newWidth + (layout.toDevicePixels(fullscreen.size.width) - (onScreenLeft + width));
}
if (height && height < layout.toDevicePixels(fullscreen.size.height) && onScreenTop + height >= layout.toDevicePixels(safeArea.origin.y) + layout.toDevicePixels(safeArea.size.height)) {
newHeight = newHeight + (layout.toDevicePixels(fullscreen.size.height) - (onScreenTop + height));
}
const frameNew = CGRectMake(layout.toDeviceIndependentPixels(newLeft), layout.toDeviceIndependentPixels(newTop), layout.toDeviceIndependentPixels(newWidth), layout.toDeviceIndependentPixels(newHeight));
nativeView.frame = frameNew;
}
}
// if (leftInset || topInset) {
// const frameNew = CGRectMake(layout.toDeviceIndependentPixels(left), layout.toDeviceIndependentPixels(top), layout.toDeviceIndependentPixels(right - left + leftInset), layout.toDeviceIndependentPixels(bottom - top + topInset));
// nativeView.frame = frameNew;
// const boundsOrigin = nativeView.bounds.origin;
// nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, frameNew.size.width, frameNew.size.height);
// }
// else {
const boundsOrigin = nativeView.bounds.origin;
nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, nativeView.frame.size.width, nativeView.frame.size.height);
// }
// }
return nativeView.frame;
}
[clipToBoundsProperty.getDefault](): boolean {
return false;
}

View File

@@ -81,8 +81,10 @@ export class StackLayout extends StackLayoutBase {
this.setMeasuredDimension(widthAndState, heightAndState);
}
public onLayout(left: number, top: number, right: number, bottom: number, insets: {left, top, right, bottom}): void {
public onLayout(left: number, top: number, right: number, bottom: number): void {
super.onLayout(left, top, right, bottom);
const insets = this.getSafeAreaInsets();
if (this.orientation === "vertical") {
this.layoutVertical(left, top, right, bottom, insets);
}
@@ -100,7 +102,6 @@ export class StackLayout extends StackLayoutBase {
let childTop: number;
let childLeft: number = paddingLeft;
let childRight = right - left - paddingRight;
// let childRight = right - paddingRight;
switch (this.verticalAlignment) {
case VerticalAlignment.MIDDLE:

View File

@@ -119,9 +119,10 @@ export class WrapLayout extends WrapLayoutBase {
this.setMeasuredDimension(widthAndState, heightAndState);
}
public onLayout(left: number, top: number, right: number, bottom: number, insets: { left, top, right, bottom }): void {
public onLayout(left: number, top: number, right: number, bottom: number): void {
super.onLayout(left, top, right, bottom);
const insets = this.getSafeAreaInsets();
const isVertical = this.orientation === "vertical";
const paddingLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left;
const paddingTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top;