fix(ios): handle tabs extended layout for ios 10

This commit is contained in:
Martin Yankov
2019-08-15 10:59:59 +03:00
parent acc3436d9f
commit f7f061202c

View File

@ -11,7 +11,7 @@ import { Font } from "../styling/font";
import { Frame } from "../frame"; import { Frame } from "../frame";
import { ios as iosView, View } from "../core/view"; import { ios as iosView, View } from "../core/view";
import { Color } from "../../color"; import { Color } from "../../color";
import { /*ios as iosUtils,*/ layout, isFontIconURI } from "../../utils/utils"; import { ios as iosUtils, layout, isFontIconURI } from "../../utils/utils";
// import { device } from "../../platform"; // import { device } from "../../platform";
import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-source"; import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-source";
@ -20,7 +20,7 @@ import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-s
export * from "./tabs-common"; export * from "./tabs-common";
// const majorVersion = iosUtils.MajorVersion; const majorVersion = iosUtils.MajorVersion;
// const isPhone = device.deviceType === "Phone"; // const isPhone = device.deviceType === "Phone";
class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate { class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate {
@ -106,6 +106,8 @@ class UIPageViewControllerImpl extends UIPageViewController {
return; return;
} }
iosView.updateAutoAdjustScrollInsets(this, owner);
// Tabs can be reset as a root view. Call loaded here in this scenario. // Tabs can be reset as a root view. Call loaded here in this scenario.
if (!owner.isLoaded) { if (!owner.isLoaded) {
owner.callLoaded(); owner.callLoaded();
@ -119,29 +121,39 @@ class UIPageViewControllerImpl extends UIPageViewController {
return; return;
} }
let safeAreaInsetsBottom = 0;
let safeAreaInsetsTop = 0;
if (majorVersion > 10) {
safeAreaInsetsBottom = this.view.safeAreaInsets.bottom;
safeAreaInsetsTop = this.view.safeAreaInsets.top;
} else {
safeAreaInsetsTop = this.topLayoutGuide.length;
}
let scrollViewTop = 0; let scrollViewTop = 0;
let scrollViewHeight = this.view.bounds.size.height + this.view.safeAreaInsets.bottom; let scrollViewHeight = this.view.bounds.size.height + safeAreaInsetsBottom;
if (owner.tabStrip) { if (owner.tabStrip) {
scrollViewTop = this.tabBar.frame.size.height; scrollViewTop = this.tabBar.frame.size.height;
scrollViewHeight = this.view.bounds.size.height - this.tabBar.frame.size.height + this.view.safeAreaInsets.bottom; scrollViewHeight = this.view.bounds.size.height - this.tabBar.frame.size.height + safeAreaInsetsBottom;
let tabBarTop = this.view.safeAreaInsets.top; let tabBarTop = safeAreaInsetsTop;
let tabBarHeight = this.tabBar.frame.size.height; let tabBarHeight = this.tabBar.frame.size.height;
const tabsPosition = owner.tabsPosition; const tabsPosition = owner.tabsPosition;
if (tabsPosition === "bottom") { if (tabsPosition === "bottom") {
tabBarTop = this.view.frame.size.height - this.tabBar.frame.size.height - this.view.safeAreaInsets.bottom; tabBarTop = this.view.frame.size.height - this.tabBar.frame.size.height - safeAreaInsetsBottom;
scrollViewTop = this.view.frame.origin.y; scrollViewTop = this.view.frame.origin.y;
scrollViewHeight = this.view.frame.size.height - this.view.safeAreaInsets.bottom; scrollViewHeight = this.view.frame.size.height - safeAreaInsetsBottom;
} }
const parent = owner.parent; const parent = owner.parent;
if (parent) { if (parent && majorVersion > 10) {
// TODO: Figure out a better way to handle ViewController nesting/Safe Area nesting // TODO: Figure out a better way to handle ViewController nesting/Safe Area nesting
tabBarTop = Math.max(tabBarTop, owner.parent.nativeView.safeAreaInsets.top); tabBarTop = Math.max(tabBarTop, owner.parent.nativeView.safeAreaInsets.top);
} }
this.tabBar.frame = CGRectMake(this.view.safeAreaInsets.left, tabBarTop, this.tabBar.frame.size.width, tabBarHeight); this.tabBar.frame = CGRectMake(0, tabBarTop, this.tabBar.frame.size.width, tabBarHeight);
} }
const subViews: NSArray<UIView> = this.view.subviews; const subViews: NSArray<UIView> = this.view.subviews;
@ -163,7 +175,7 @@ class UIPageViewControllerImpl extends UIPageViewController {
scrollView.scrollEnabled = false; scrollView.scrollEnabled = false;
} }
scrollView.frame = CGRectMake(this.view.safeAreaInsets.left, scrollViewTop, this.view.bounds.size.width, scrollViewHeight); //this.view.bounds; scrollView.frame = CGRectMake(0, scrollViewTop, this.view.bounds.size.width, scrollViewHeight); //this.view.bounds;
} }
} }
} }