From 429ac8712f192318f517b7c54c8d00fbebddbb32 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Wed, 22 Aug 2018 14:37:51 +0300 Subject: [PATCH] feat: add iosExpandSafeArea property Also apply insets on page's children. --- tns-core-modules/ui/core/view/view.android.ts | 2 +- tns-core-modules/ui/core/view/view.d.ts | 5 ++++- tns-core-modules/ui/core/view/view.ios.ts | 9 ++++++++- tns-core-modules/ui/page/page.ios.ts | 12 +++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 5c61475ae..37f35fc9d 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -817,7 +817,7 @@ export class View extends ViewCommon { } export class ContainerView extends View { - // + public iosExpandSafeArea: boolean; } export class CustomLayoutView extends ContainerView implements CustomLayoutViewDefinition { diff --git a/tns-core-modules/ui/core/view/view.d.ts b/tns-core-modules/ui/core/view/view.d.ts index c3f1b4d28..1c6ae1746 100644 --- a/tns-core-modules/ui/core/view/view.d.ts +++ b/tns-core-modules/ui/core/view/view.d.ts @@ -728,7 +728,10 @@ export abstract class View extends ViewBase { * Base class for all UI components that are containers. */ export class ContainerView extends View { - + /** + * Instruct container view to expand the safe area. This property is iOS specific. Default value: true + */ + public iosExpandSafeArea: boolean; } /** diff --git a/tns-core-modules/ui/core/view/view.ios.ts b/tns-core-modules/ui/core/view/view.ios.ts index 911419367..69bd0894c 100644 --- a/tns-core-modules/ui/core/view/view.ios.ts +++ b/tns-core-modules/ui/core/view/view.ios.ts @@ -1,6 +1,7 @@ // Definitions. import { Point, View as ViewDefinition, dip } from "."; import { ViewBase } from "../view-base"; +import { booleanConverter, Property } from "../view"; import { ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty, @@ -607,8 +608,11 @@ export class View extends ViewCommon { View.prototype._nativeBackgroundState = "unset"; export class ContainerView extends View { + + public iosExpandSafeArea: boolean; + protected applySafeAreaInsets(frame: CGRect): CGRect { - if (majorVersion > 10) { + if (this.iosExpandSafeArea && majorVersion > 10) { const locationOnScreen = this.getLocationOnScreen(); if (locationOnScreen) { @@ -648,6 +652,9 @@ export class ContainerView extends View { } } +export const iosExpandSafeAreaProperty = new Property({ name: "iosExpandSafeArea", defaultValue: true, valueConverter: booleanConverter }); +iosExpandSafeAreaProperty.register(ContainerView); + export class CustomLayoutView extends ContainerView { nativeViewProtected: UIView; diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 6f57c2c17..e3056a9af 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -120,7 +120,7 @@ class UIViewControllerImpl extends UIViewController { // Skip navigation events if modal page is shown. if (!owner._presentedViewController && frame) { const newEntry = this[ENTRY]; - + let isBack: boolean; // We are on the current page which happens when navigation is canceled so isBack should be false. if (frame.currentPage === owner && frame._navigationQueue.length === 0) { @@ -309,7 +309,13 @@ export class Page extends PageBase { public onLayout(left: number, top: number, right: number, bottom: number) { const { width: actionBarWidth, height: actionBarHeight } = this.actionBar._getActualSize; View.layoutChild(this, this.actionBar, 0, 0, actionBarWidth, actionBarHeight); - View.layoutChild(this, this.layoutView, left, top, right, bottom); + + const insets = this.getSafeAreaInsets(); + const childLeft = left + insets.left; + const childTop = top + insets.top; + const childRight = right - insets.right; + const childBottom = bottom - insets.bottom; + View.layoutChild(this, this.layoutView, childLeft, childTop, childRight, childBottom); } public _addViewToNativeVisualTree(child: View, atIndex: number): boolean { @@ -327,7 +333,7 @@ export class Page extends PageBase { if (this.viewController.presentedViewController === viewController) { return true; } - + this.viewController.addChildViewController(viewController); }