mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: add iosExpandSafeArea property
Also apply insets on page's children.
This commit is contained in:
committed by
Martin Yankov
parent
ec98fd6f5f
commit
429ac8712f
@@ -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 {
|
||||||
|
|||||||
5
tns-core-modules/ui/core/view/view.d.ts
vendored
5
tns-core-modules/ui/core/view/view.d.ts
vendored
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user