mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix-next: ios 10 safe area backwards compat (#6364)
* fix-next: ios 10 safe area backwards compat * refactor: update a comment * fix-next: ios 10 page on layout fix * fix-next: handle ios 11 flat action bar
This commit is contained in:
@@ -698,16 +698,18 @@ export namespace ios {
|
||||
}
|
||||
|
||||
export function layoutView(controller: UIViewController, owner: View): void {
|
||||
// apply parent page additional top insets if any. The scenario is when there is a parent page with action bar.
|
||||
const parentPage = getAncestor(owner, "Page");
|
||||
if (parentPage) {
|
||||
const parentPageInsetsTop = parentPage.viewController.view.safeAreaInsets.top;
|
||||
const currentInsetsTop = controller.view.safeAreaInsets.top;
|
||||
const additionalInsetsTop = parentPageInsetsTop - currentInsetsTop;
|
||||
if (majorVersion >= 11) {
|
||||
// apply parent page additional top insets if any. The scenario is when there is a parent page with action bar.
|
||||
const parentPage = getAncestor(owner, "Page");
|
||||
if (parentPage) {
|
||||
const parentPageInsetsTop = parentPage.viewController.view.safeAreaInsets.top;
|
||||
const currentInsetsTop = controller.view.safeAreaInsets.top;
|
||||
const additionalInsetsTop = parentPageInsetsTop - currentInsetsTop;
|
||||
|
||||
if (additionalInsetsTop > 0) {
|
||||
const additionalInsets = new UIEdgeInsets({ top: additionalInsetsTop, left: 0, bottom: 0, right: 0 });
|
||||
controller.additionalSafeAreaInsets = additionalInsets;
|
||||
if (additionalInsetsTop > 0) {
|
||||
const additionalInsets = new UIEdgeInsets({ top: additionalInsetsTop, left: 0, bottom: 0, right: 0 });
|
||||
controller.additionalSafeAreaInsets = additionalInsets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,15 @@ import {
|
||||
} from "./page-common";
|
||||
|
||||
import { profile } from "../../profiling";
|
||||
import { ios as iosUtils } from "../../utils/utils";
|
||||
|
||||
export * from "./page-common";
|
||||
|
||||
const ENTRY = "_entry";
|
||||
const DELEGATE = "_delegate";
|
||||
|
||||
const majorVersion = iosUtils.MajorVersion;
|
||||
|
||||
function isBackNavigationTo(page: Page, entry): boolean {
|
||||
const frame = page.frame;
|
||||
if (!frame) {
|
||||
@@ -315,10 +318,23 @@ export class Page extends PageBase {
|
||||
|
||||
const insets = this.getSafeAreaInsets();
|
||||
|
||||
if (majorVersion <= 10) {
|
||||
// iOS 10 and below don't have safe area insets API,
|
||||
// there we need only the top inset on the Page
|
||||
insets.top = layout.round(layout.toDevicePixels(this.viewController.view.safeAreaLayoutGuide.layoutFrame.origin.y));
|
||||
}
|
||||
|
||||
const childLeft = 0 + insets.left;
|
||||
const childTop = 0 + insets.top;
|
||||
const childRight = right - left - insets.right;
|
||||
const childBottom = bottom - top - insets.bottom;
|
||||
const childRight = right - insets.right;
|
||||
let childBottom = bottom - insets.bottom;
|
||||
|
||||
if (majorVersion >= 11 && this.actionBar.flat) {
|
||||
// on iOS 11 the flat action bar changes the fullscreen size
|
||||
// the top of the page is the new fullscreen
|
||||
childBottom -= top;
|
||||
}
|
||||
|
||||
View.layoutChild(this, this.layoutView, childLeft, childTop, childRight, childBottom);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user