diff --git a/tns-core-modules/ui/core/view/view-common.ts b/tns-core-modules/ui/core/view/view-common.ts index 53790ad6e..7d8d20e0a 100644 --- a/tns-core-modules/ui/core/view/view-common.ts +++ b/tns-core-modules/ui/core/view/view-common.ts @@ -586,6 +586,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { public originY: number; public isEnabled: boolean; public isUserInteractionEnabled: boolean; + public iosExpandSafeArea: boolean; get isLayoutValid(): boolean { return this._isLayoutValid; @@ -1021,6 +1022,9 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { } } +export const iosExpandSafeAreaProperty = new Property({ name: "iosExpandSafeArea", defaultValue: false, valueConverter: booleanConverter }); +iosExpandSafeAreaProperty.register(ViewCommon); + export const automationTextProperty = new Property({ name: "automationText" }); automationTextProperty.register(ViewCommon); diff --git a/tns-core-modules/ui/core/view/view.ios.ts b/tns-core-modules/ui/core/view/view.ios.ts index 69bd0894c..859edbd77 100644 --- a/tns-core-modules/ui/core/view/view.ios.ts +++ b/tns-core-modules/ui/core/view/view.ios.ts @@ -221,7 +221,11 @@ export class View extends ViewCommon { } protected applySafeAreaInsets(frame: CGRect): CGRect { - if (majorVersion > 10) { + if (majorVersion <= 10) { + return null; + } + + if (!this.iosExpandSafeArea) { const insets = this.getSafeAreaInsets(); if (insets.left || insets.top) { @@ -229,6 +233,40 @@ export class View extends ViewCommon { const adjustedFrame = this.getFrameFromPosition(position, insets); 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; @@ -611,50 +649,12 @@ export class ContainerView extends View { public iosExpandSafeArea: boolean; - protected applySafeAreaInsets(frame: CGRect): CGRect { - if (this.iosExpandSafeArea && majorVersion > 10) { - 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; + constructor() { + super(); + this.iosExpandSafeArea = true; } } -export const iosExpandSafeAreaProperty = new Property({ name: "iosExpandSafeArea", defaultValue: true, valueConverter: booleanConverter }); -iosExpandSafeAreaProperty.register(ContainerView); - export class CustomLayoutView extends ContainerView { nativeViewProtected: UIView;