feat: add iosExpandSafeArea property

Also apply insets on page's children.
This commit is contained in:
Vasil Chimev
2018-08-22 14:37:51 +03:00
committed by Martin Yankov
parent ec98fd6f5f
commit 429ac8712f
4 changed files with 22 additions and 6 deletions

View File

@@ -817,7 +817,7 @@ export class View extends ViewCommon {
} }
export class ContainerView extends View { export class ContainerView extends View {
// public iosExpandSafeArea: boolean;
} }
export class CustomLayoutView extends ContainerView implements CustomLayoutViewDefinition { export class CustomLayoutView extends ContainerView implements CustomLayoutViewDefinition {

View File

@@ -728,7 +728,10 @@ export abstract class View extends ViewBase {
* Base class for all UI components that are containers. * Base class for all UI components that are containers.
*/ */
export class ContainerView extends View { export class ContainerView extends View {
/**
* Instruct container view to expand the safe area. This property is iOS specific. Default value: true
*/
public iosExpandSafeArea: boolean;
} }
/** /**

View File

@@ -1,6 +1,7 @@
// Definitions. // Definitions.
import { Point, View as ViewDefinition, dip } from "."; import { Point, View as ViewDefinition, dip } from ".";
import { ViewBase } from "../view-base"; import { ViewBase } from "../view-base";
import { booleanConverter, Property } from "../view";
import { import {
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty, ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
@@ -607,8 +608,11 @@ export class View extends ViewCommon {
View.prototype._nativeBackgroundState = "unset"; View.prototype._nativeBackgroundState = "unset";
export class ContainerView extends View { export class ContainerView extends View {
public iosExpandSafeArea: boolean;
protected applySafeAreaInsets(frame: CGRect): CGRect { protected applySafeAreaInsets(frame: CGRect): CGRect {
if (majorVersion > 10) { if (this.iosExpandSafeArea && majorVersion > 10) {
const locationOnScreen = this.getLocationOnScreen(); const locationOnScreen = this.getLocationOnScreen();
if (locationOnScreen) { if (locationOnScreen) {
@@ -648,6 +652,9 @@ export class ContainerView extends View {
} }
} }
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;

View File

@@ -120,7 +120,7 @@ class UIViewControllerImpl extends UIViewController {
// Skip navigation events if modal page is shown. // Skip navigation events if modal page is shown.
if (!owner._presentedViewController && frame) { if (!owner._presentedViewController && frame) {
const newEntry = this[ENTRY]; const newEntry = this[ENTRY];
let isBack: boolean; let isBack: boolean;
// We are on the current page which happens when navigation is canceled so isBack should be false. // 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) { 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) { public onLayout(left: number, top: number, right: number, bottom: number) {
const { width: actionBarWidth, height: actionBarHeight } = this.actionBar._getActualSize; const { width: actionBarWidth, height: actionBarHeight } = this.actionBar._getActualSize;
View.layoutChild(this, this.actionBar, 0, 0, actionBarWidth, actionBarHeight); 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 { public _addViewToNativeVisualTree(child: View, atIndex: number): boolean {
@@ -327,7 +333,7 @@ export class Page extends PageBase {
if (this.viewController.presentedViewController === viewController) { if (this.viewController.presentedViewController === viewController) {
return true; return true;
} }
this.viewController.addChildViewController(viewController); this.viewController.addChildViewController(viewController);
} }