fix(layouts): Set automaticallyAdjustsScrollViewInsets (#5311)

This commit is contained in:
Alexander Vakrilov
2018-01-23 17:53:31 +02:00
committed by Svetoslav
parent 58d61caf59
commit b492996647
4 changed files with 77 additions and 66 deletions

View File

@ -768,6 +768,8 @@ export const isEnabledProperty: Property<View, boolean>;
export const isUserInteractionEnabledProperty: Property<View, boolean>; export const isUserInteractionEnabledProperty: Property<View, boolean>;
export namespace ios { export namespace ios {
export function isContentScrollable(controller: any /* UIViewController */, owner: View): boolean
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void
export function updateConstraints(controller: any /* UIViewController */, owner: View): void; export function updateConstraints(controller: any /* UIViewController */, owner: View): void;
export function layoutView(controller: any /* UIViewController */, owner: View): void; export function layoutView(controller: any /* UIViewController */, owner: View): void;
export class UILayoutViewController { export class UILayoutViewController {

View File

@ -575,21 +575,26 @@ export class CustomLayoutView extends View {
} }
} }
function isScrollable(controller: UIViewController, owner: View): boolean {
let scrollable = (<any>owner).scrollableContent;
if (scrollable === undefined) {
const view: UIView = controller.view.subviews.count > 0 ? controller.view.subviews[0] : null;
if (view instanceof UIScrollView) {
scrollable = true;
}
}
return scrollable === true || scrollable === "true";;
}
const majorVersion = iosUtils.MajorVersion; const majorVersion = iosUtils.MajorVersion;
export namespace ios { export namespace ios {
export function isContentScrollable(controller: UIViewController, owner: View): boolean {
let scrollableContent = (<any>owner).scrollableContent;
if (scrollableContent === undefined) {
const view: UIView = controller.view.subviews.count > 0 ? controller.view.subviews[0] : null;
if (view instanceof UIScrollView) {
scrollableContent = true;
}
}
return scrollableContent === true || scrollableContent === "true";;
}
export function updateAutoAdjustScrollInsets(controller: UIViewController, owner: View): void {
const scrollable = isContentScrollable(controller, owner);
controller.automaticallyAdjustsScrollViewInsets = scrollable;
}
export function updateConstraints(controller: UIViewController, owner: View): void { export function updateConstraints(controller: UIViewController, owner: View): void {
const root = controller.view; const root = controller.view;
if (!root.safeAreaLayoutGuide) { if (!root.safeAreaLayoutGuide) {
@ -619,28 +624,18 @@ export namespace ios {
} }
export function layoutView(controller: UIViewController, owner: View): void { export function layoutView(controller: UIViewController, owner: View): void {
const fullscreen = controller ===
iosUtils.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController;
let left: number, top: number, width: number, height: number; let left: number, top: number, width: number, height: number;
const frame = controller.view.frame; const frame = controller.view.frame;
const fullscreenOrigin = frame.origin; const fullscreenOrigin = frame.origin;
const fullscreenSize = frame.size; const fullscreenSize = frame.size;
if (fullscreen) {
left = layout.toDevicePixels(fullscreenOrigin.x);
top = layout.toDevicePixels(fullscreenOrigin.y);
width = layout.toDevicePixels(fullscreenSize.width);
height = layout.toDevicePixels(fullscreenSize.height);
} else {
const safeArea = controller.view.safeAreaLayoutGuide.layoutFrame; const safeArea = controller.view.safeAreaLayoutGuide.layoutFrame;
const safeOrigin = safeArea.origin; const safeOrigin = safeArea.origin;
const safeAreaSize = safeArea.size; const safeAreaSize = safeArea.size;
const navController = controller.navigationController; const navController = controller.navigationController;
const navBarHidden = navController ? navController.navigationBarHidden : true; const navBarHidden = navController ? navController.navigationBarHidden : true;
const scrollable = isScrollable(controller, owner); const scrollable = isContentScrollable(controller, owner);
const hasChildControllers = controller.childViewControllers.count > 0; const hasChildControllers = controller.childViewControllers.count > 0;
const safeAreaTopLength = safeOrigin.y - fullscreenOrigin.y; const safeAreaTopLength = safeOrigin.y - fullscreenOrigin.y;
@ -678,7 +673,6 @@ export namespace ios {
top = layout.toDevicePixels(top); top = layout.toDevicePixels(top);
width = layout.toDevicePixels(width); width = layout.toDevicePixels(width);
height = layout.toDevicePixels(height); height = layout.toDevicePixels(height);
}
const widthSpec = layout.makeMeasureSpec(width, layout.EXACTLY); const widthSpec = layout.makeMeasureSpec(width, layout.EXACTLY);
const heightSpec = layout.makeMeasureSpec(height, layout.EXACTLY); const heightSpec = layout.makeMeasureSpec(height, layout.EXACTLY);
@ -736,7 +730,13 @@ export namespace ios {
public viewWillAppear(animated: boolean): void { public viewWillAppear(animated: boolean): void {
super.viewWillAppear(animated); super.viewWillAppear(animated);
const owner = this.owner.get(); const owner = this.owner.get();
if (owner && !owner.parent) { if(!owner){
return;
}
updateAutoAdjustScrollInsets(this, owner);
if (!owner.parent) {
owner.callLoaded(); owner.callLoaded();
} }
} }

View File

@ -106,6 +106,9 @@ class UIViewControllerImpl extends UIViewController {
frame._updateActionBar(owner); frame._updateActionBar(owner);
} }
// Set autoAdjustScrollInsets in will appear - as early as possible
iosView.updateAutoAdjustScrollInsets(this, owner);
// Pages in backstack are unloaded so raise loaded here. // Pages in backstack are unloaded so raise loaded here.
if (!owner.isLoaded) { if (!owner.isLoaded) {
owner.callLoaded(); owner.callLoaded();

View File

@ -32,7 +32,13 @@ class UITabBarControllerImpl extends UITabBarController {
public viewWillAppear(animated: boolean): void { public viewWillAppear(animated: boolean): void {
super.viewWillAppear(animated); super.viewWillAppear(animated);
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && !owner.parent) { if(!owner){
return;
}
iosView.updateAutoAdjustScrollInsets(this, owner);
if (!owner.parent) {
owner.callLoaded(); owner.callLoaded();
} }
} }