enable iosExpandSafeArea property on Views too

This commit is contained in:
Martin Yankov
2018-08-23 19:20:23 +03:00
parent d9f350a75d
commit ee004b4580
2 changed files with 46 additions and 42 deletions

View File

@@ -586,6 +586,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
public originY: number; public originY: number;
public isEnabled: boolean; public isEnabled: boolean;
public isUserInteractionEnabled: boolean; public isUserInteractionEnabled: boolean;
public iosExpandSafeArea: boolean;
get isLayoutValid(): boolean { get isLayoutValid(): boolean {
return this._isLayoutValid; return this._isLayoutValid;
@@ -1021,6 +1022,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
} }
} }
export const iosExpandSafeAreaProperty = new Property<ViewCommon, boolean>({ name: "iosExpandSafeArea", defaultValue: false, valueConverter: booleanConverter });
iosExpandSafeAreaProperty.register(ViewCommon);
export const automationTextProperty = new Property<ViewCommon, string>({ name: "automationText" }); export const automationTextProperty = new Property<ViewCommon, string>({ name: "automationText" });
automationTextProperty.register(ViewCommon); automationTextProperty.register(ViewCommon);

View File

@@ -221,7 +221,11 @@ export class View extends ViewCommon {
} }
protected applySafeAreaInsets(frame: CGRect): CGRect { protected applySafeAreaInsets(frame: CGRect): CGRect {
if (majorVersion > 10) { if (majorVersion <= 10) {
return null;
}
if (!this.iosExpandSafeArea) {
const insets = this.getSafeAreaInsets(); const insets = this.getSafeAreaInsets();
if (insets.left || insets.top) { if (insets.left || insets.top) {
@@ -229,6 +233,40 @@ export class View extends ViewCommon {
const adjustedFrame = this.getFrameFromPosition(position, insets); const adjustedFrame = this.getFrameFromPosition(position, insets);
return adjustedFrame; return adjustedFrame;
} }
} else {
const locationOnScreen = this.getLocationOnScreen();
if (locationOnScreen) {
const safeArea = this.getSafeArea();
const fullscreen = this.getFullscreenArea();
const onScreenLeft = layout.round(layout.toDevicePixels(locationOnScreen.x));
const onScreenTop = layout.round(layout.toDevicePixels(locationOnScreen.y));
const position = this.getPositionFromFrame(frame);
const safeAreaPosition = this.getPositionFromFrame(safeArea);
const fullscreenPosition = this.getPositionFromFrame(fullscreen);
const adjustedPosition = position;
if (position.left && onScreenLeft <= safeAreaPosition.left) {
adjustedPosition.left = fullscreenPosition.left;
}
if (position.top && onScreenTop <= safeAreaPosition.top) {
adjustedPosition.top = fullscreenPosition.top;
}
if (position.right < fullscreenPosition.right && position.right >= safeAreaPosition.right) {
adjustedPosition.right = fullscreenPosition.right;
}
if (position.bottom < fullscreenPosition.bottom && position.bottom >= safeAreaPosition.bottom) {
adjustedPosition.bottom = fullscreenPosition.bottom;
}
const adjustedFrame = CGRectMake(layout.toDeviceIndependentPixels(adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.top), layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top));
return adjustedFrame;
}
} }
return null; return null;
@@ -611,50 +649,12 @@ export class ContainerView extends View {
public iosExpandSafeArea: boolean; public iosExpandSafeArea: boolean;
protected applySafeAreaInsets(frame: CGRect): CGRect { constructor() {
if (this.iosExpandSafeArea && majorVersion > 10) { super();
const locationOnScreen = this.getLocationOnScreen(); this.iosExpandSafeArea = true;
if (locationOnScreen) {
const safeArea = this.getSafeArea();
const fullscreen = this.getFullscreenArea();
const onScreenLeft = layout.round(layout.toDevicePixels(locationOnScreen.x));
const onScreenTop = layout.round(layout.toDevicePixels(locationOnScreen.y));
const position = this.getPositionFromFrame(frame);
const safeAreaPosition = this.getPositionFromFrame(safeArea);
const fullscreenPosition = this.getPositionFromFrame(fullscreen);
const adjustedPosition = position;
if (position.left && onScreenLeft <= safeAreaPosition.left) {
adjustedPosition.left = fullscreenPosition.left;
}
if (position.top && onScreenTop <= safeAreaPosition.top) {
adjustedPosition.top = fullscreenPosition.top;
}
if (position.right < fullscreenPosition.right && position.right >= safeAreaPosition.right) {
adjustedPosition.right = fullscreenPosition.right;
}
if (position.bottom < fullscreenPosition.bottom && position.bottom >= safeAreaPosition.bottom) {
adjustedPosition.bottom = fullscreenPosition.bottom;
}
const adjustedFrame = CGRectMake(layout.toDeviceIndependentPixels(adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.top), layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top));
return adjustedFrame;
}
}
return null;
} }
} }
export const iosExpandSafeAreaProperty = new Property<ContainerView, boolean>({ name: "iosExpandSafeArea", defaultValue: true, valueConverter: booleanConverter });
iosExpandSafeAreaProperty.register(ContainerView);
export class CustomLayoutView extends ContainerView { export class CustomLayoutView extends ContainerView {
nativeViewProtected: UIView; nativeViewProtected: UIView;