FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios): safeAreaLayoutGuide fallback for iOS 10 cases (#5960) · NativeScript/NativeScript@4b5754a · GitHub

Commit 4b5754a

Browse files
Alexander Vakrilov
authored
fix(ios): safeAreaLayoutGuide fallback for iOS 10 cases (#5960)
1 parent d79ac30 commit 4b5754a

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

‎tns-core-modules/ui/core/view/view.ios.ts‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ViewBase } from "../view-base";
44

55
import {
66
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
7-
traceEnabled, traceWrite, traceCategories
7+
traceEnabled, traceWrite, traceCategories, traceMessageType
88
} from "./view-common";
99

1010
import { ios as iosBackground, Background } from "../../styling/background";
@@ -615,17 +615,24 @@ export namespace ios {
615615
export function updateConstraints(controller: UIViewController, owner: View): void {
616616
const root = controller.view;
617617
if (!root.safeAreaLayoutGuide) {
618-
const layoutGuide = (<any>root).safeAreaLayoutGuide = UILayoutGuide.alloc().init();
619-
root.addLayoutGuide(layoutGuide);
620-
NSLayoutConstraint.activateConstraints(<any>[
621-
layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor),
622-
layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor),
623-
layoutGuide.leadingAnchor.constraintEqualToAnchor(root.leadingAnchor),
624-
layoutGuide.trailingAnchor.constraintEqualToAnchor(root.trailingAnchor)
625-
]);
618+
const layoutGuide = initLayoutGuide(controller);
619+
(<any>controller.view).safeAreaLayoutGuide = layoutGuide;
626620
}
627621
}
628622

623+
function initLayoutGuide(controller: UIViewController) {
624+
const rootView = controller.view;
625+
const layoutGuide = UILayoutGuide.alloc().init();
626+
rootView.addLayoutGuide(layoutGuide);
627+
NSLayoutConstraint.activateConstraints(<any>[
628+
layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor),
629+
layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor),
630+
layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor),
631+
layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)
632+
]);
633+
return layoutGuide;
634+
}
635+
629636
function getStatusBarHeight(viewController?: UIViewController): number {
630637
const app = iosUtils.getter(UIApplication, UIApplication.sharedApplication);
631638
if (!app || app.statusBarHidden) {
@@ -646,7 +653,15 @@ export namespace ios {
646653
const frame = controller.view.frame;
647654
const fullscreenOrigin = frame.origin;
648655
const fullscreenSize = frame.size;
649-
const safeArea = controller.view.safeAreaLayoutGuide.layoutFrame;
656+
657+
let layoutGuide = controller.view.safeAreaLayoutGuide;
658+
if (!layoutGuide) {
659+
traceWrite(`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`,
660+
traceCategories.Layout, traceMessageType.error);
661+
662+
layoutGuide = initLayoutGuide(controller);
663+
}
664+
const safeArea = layoutGuide.layoutFrame;
650665
const safeOrigin = safeArea.origin;
651666
const safeAreaSize = safeArea.size;
652667

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL