mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor: View.applySafeAreaInsets(frame)
Split to `ios.shrinkToSafeArea()` and `ios.expandBeyondSafeArea()`. Update trace logs.
This commit is contained in:
committed by
Martin Yankov
parent
bf070f105d
commit
f2d9b05e01
@@ -226,52 +226,9 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.iosExpandSafeArea) {
|
if (!this.iosExpandSafeArea) {
|
||||||
const insets = this.getSafeAreaInsets();
|
return ios.shrinkToSafeArea(this, frame);
|
||||||
|
|
||||||
if (insets.left || insets.top) {
|
|
||||||
const position = ios.getPositionFromFrame(frame);
|
|
||||||
const adjustedFrame = ios.getFrameFromPosition(position, insets);
|
|
||||||
|
|
||||||
if (traceEnabled()) {
|
|
||||||
traceWrite(this + " :applySafeAreaInsets: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
return adjustedFrame;
|
|
||||||
}
|
|
||||||
} else if (this.nativeViewProtected && this.nativeViewProtected.window) {
|
} else if (this.nativeViewProtected && this.nativeViewProtected.window) {
|
||||||
const parentWithController = ios.getParentWithViewController(this);
|
return ios.expandBeyondSafeArea(this, frame);
|
||||||
const safeArea = parentWithController.viewController.view.safeAreaLayoutGuide.layoutFrame;
|
|
||||||
const fullscreen = parentWithController.viewController.view.frame;
|
|
||||||
|
|
||||||
const position = ios.getPositionFromFrame(frame);
|
|
||||||
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
|
|
||||||
const fullscreenPosition = ios.getPositionFromFrame(fullscreen);
|
|
||||||
|
|
||||||
const adjustedPosition = position;
|
|
||||||
|
|
||||||
if (position.left && position.left <= safeAreaPosition.left) {
|
|
||||||
adjustedPosition.left = fullscreenPosition.left;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (position.top && position.top <= 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));
|
|
||||||
|
|
||||||
if (traceEnabled()) {
|
|
||||||
traceWrite(this + " :applySafeAreaInsets: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
return adjustedFrame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -797,6 +754,58 @@ export namespace ios {
|
|||||||
return CGRectMake(left, top, width, height);
|
return CGRectMake(left, top, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shrinkToSafeArea(view: View, frame: CGRect): CGRect {
|
||||||
|
const insets = view.getSafeAreaInsets();
|
||||||
|
if (insets.left || insets.top) {
|
||||||
|
const position = ios.getPositionFromFrame(frame);
|
||||||
|
const adjustedFrame = ios.getFrameFromPosition(position, insets);
|
||||||
|
|
||||||
|
if (traceEnabled()) {
|
||||||
|
traceWrite(this + " :shrinkToSafeArea: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return adjustedFrame;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function expandBeyondSafeArea(view: View, frame: CGRect): CGRect {
|
||||||
|
const parentWithController = ios.getParentWithViewController(view);
|
||||||
|
const safeArea = parentWithController.viewController.view.safeAreaLayoutGuide.layoutFrame;
|
||||||
|
const fullscreen = parentWithController.viewController.view.frame;
|
||||||
|
|
||||||
|
const position = ios.getPositionFromFrame(frame);
|
||||||
|
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
|
||||||
|
const fullscreenPosition = ios.getPositionFromFrame(fullscreen);
|
||||||
|
|
||||||
|
const adjustedPosition = position;
|
||||||
|
|
||||||
|
if (position.left && position.left <= safeAreaPosition.left) {
|
||||||
|
adjustedPosition.left = fullscreenPosition.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position.top && position.top <= 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));
|
||||||
|
|
||||||
|
if (traceEnabled()) {
|
||||||
|
traceWrite(view + " :expandBeyondSafeArea: " + JSON.stringify(ios.getPositionFromFrame(adjustedFrame)), traceCategories.Layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return adjustedFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function layoutParent(view: ViewBase): void {
|
function layoutParent(view: ViewBase): void {
|
||||||
if (!view) {
|
if (!view) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user