mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: iosIgnoreSafeArea property (#9092)
* feat: ios added ignoreSafeArea property * fix: ensure it works when no viewControllerView
This commit is contained in:
@@ -262,7 +262,9 @@ export class View extends ViewCommon implements ViewDefinition {
|
|||||||
if (majorVersion <= 10) {
|
if (majorVersion <= 10) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (this.iosIgnoreSafeArea) {
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
if (!this.iosOverflowSafeArea || !this.iosOverflowSafeAreaEnabled) {
|
if (!this.iosOverflowSafeArea || !this.iosOverflowSafeAreaEnabled) {
|
||||||
return IOSHelper.shrinkToSafeArea(this, frame);
|
return IOSHelper.shrinkToSafeArea(this, frame);
|
||||||
} else if (this.nativeViewProtected && this.nativeViewProtected.window) {
|
} else if (this.nativeViewProtected && this.nativeViewProtected.window) {
|
||||||
@@ -275,7 +277,9 @@ export class View extends ViewCommon implements ViewDefinition {
|
|||||||
public getSafeAreaInsets(): { left; top; right; bottom } {
|
public getSafeAreaInsets(): { left; top; right; bottom } {
|
||||||
const safeAreaInsets = this.nativeViewProtected && this.nativeViewProtected.safeAreaInsets;
|
const safeAreaInsets = this.nativeViewProtected && this.nativeViewProtected.safeAreaInsets;
|
||||||
const insets = { left: 0, top: 0, right: 0, bottom: 0 };
|
const insets = { left: 0, top: 0, right: 0, bottom: 0 };
|
||||||
|
if (this.iosIgnoreSafeArea) {
|
||||||
|
return insets;
|
||||||
|
}
|
||||||
if (safeAreaInsets) {
|
if (safeAreaInsets) {
|
||||||
insets.left = layout.round(layout.toDevicePixels(safeAreaInsets.left));
|
insets.left = layout.round(layout.toDevicePixels(safeAreaInsets.left));
|
||||||
insets.top = layout.round(layout.toDevicePixels(safeAreaInsets.top));
|
insets.top = layout.round(layout.toDevicePixels(safeAreaInsets.top));
|
||||||
|
|||||||
@@ -758,7 +758,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
|||||||
public isUserInteractionEnabled: boolean;
|
public isUserInteractionEnabled: boolean;
|
||||||
public iosOverflowSafeArea: boolean;
|
public iosOverflowSafeArea: boolean;
|
||||||
public iosOverflowSafeAreaEnabled: boolean;
|
public iosOverflowSafeAreaEnabled: boolean;
|
||||||
|
public iosIgnoreSafeArea: boolean;
|
||||||
|
|
||||||
get isLayoutValid(): boolean {
|
get isLayoutValid(): boolean {
|
||||||
return this._isLayoutValid;
|
return this._isLayoutValid;
|
||||||
}
|
}
|
||||||
@@ -1055,3 +1056,9 @@ export const iosOverflowSafeAreaEnabledProperty = new InheritedProperty<ViewComm
|
|||||||
valueConverter: booleanConverter,
|
valueConverter: booleanConverter,
|
||||||
});
|
});
|
||||||
iosOverflowSafeAreaEnabledProperty.register(ViewCommon);
|
iosOverflowSafeAreaEnabledProperty.register(ViewCommon);
|
||||||
|
export const iosIgnoreSafeAreaProperty = new InheritedProperty({
|
||||||
|
name: 'iosIgnoreSafeArea',
|
||||||
|
defaultValue: false,
|
||||||
|
valueConverter: booleanConverter,
|
||||||
|
});
|
||||||
|
iosIgnoreSafeAreaProperty.register(ViewCommon);
|
||||||
@@ -338,19 +338,23 @@ export class IOSHelper {
|
|||||||
|
|
||||||
let fullscreen = null;
|
let fullscreen = null;
|
||||||
let safeArea = null;
|
let safeArea = null;
|
||||||
|
let controllerInWindow = {x: 0, y: 0};
|
||||||
|
|
||||||
if (viewControllerView) {
|
if (viewControllerView) {
|
||||||
safeArea = viewControllerView.safeAreaLayoutGuide.layoutFrame;
|
safeArea = viewControllerView.safeAreaLayoutGuide.layoutFrame;
|
||||||
fullscreen = viewControllerView.frame;
|
fullscreen = viewControllerView.frame;
|
||||||
|
controllerInWindow = viewControllerView.convertPointToView(viewControllerView.bounds.origin, null);
|
||||||
} else if (scrollView) {
|
} else if (scrollView) {
|
||||||
const insets = scrollView.safeAreaInsets;
|
const insets = scrollView.safeAreaInsets;
|
||||||
safeArea = CGRectMake(insets.left, insets.top, scrollView.contentSize.width - insets.left - insets.right, scrollView.contentSize.height - insets.top - insets.bottom);
|
safeArea = CGRectMake(insets.left, insets.top, scrollView.contentSize.width - insets.left - insets.right, scrollView.contentSize.height - insets.top - insets.bottom);
|
||||||
fullscreen = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
|
fullscreen = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We take into account the controller position inside the window.
|
||||||
|
// for example with a bottomsheet the controller will be "offset"
|
||||||
const locationInWindow = view.getLocationInWindow();
|
const locationInWindow = view.getLocationInWindow();
|
||||||
let inWindowLeft = locationInWindow.x;
|
let inWindowLeft = locationInWindow.x - controllerInWindow.x;
|
||||||
let inWindowTop = locationInWindow.y;
|
let inWindowTop = locationInWindow.y - controllerInWindow.y;
|
||||||
|
|
||||||
if (scrollView) {
|
if (scrollView) {
|
||||||
inWindowLeft += scrollView.contentOffset.x;
|
inWindowLeft += scrollView.contentOffset.x;
|
||||||
|
|||||||
Reference in New Issue
Block a user