From 21bcb6f268beb485fdabf77111c4000333c8b685 Mon Sep 17 00:00:00 2001 From: Marco Cancellieri Date: Thu, 14 Mar 2019 18:03:25 +0100 Subject: [PATCH 1/2] Add Intrinsic Height --- PanModal/Presentable/PanModalHeight.swift | 4 ++++ .../Presentable/PanModalPresentable+LayoutHelpers.swift | 6 ++++++ .../StackedProfileViewController.swift | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/PanModal/Presentable/PanModalHeight.swift b/PanModal/Presentable/PanModalHeight.swift index 6949d9b..fae6dd6 100644 --- a/PanModal/Presentable/PanModalHeight.swift +++ b/PanModal/Presentable/PanModalHeight.swift @@ -35,4 +35,8 @@ public enum PanModalHeight: Equatable { */ case contentHeightIgnoringSafeArea(CGFloat) + /** + Sets the height to be the intrinsic content height + */ + case intrinsicHeight } diff --git a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift index 3de96f7..d56a3ef 100644 --- a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift +++ b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift @@ -90,6 +90,12 @@ extension PanModalPresentable where Self: UIViewController { return bottomYPos - (height + bottomLayoutOffset) case .contentHeightIgnoringSafeArea(let height): return bottomYPos - height + case .intrinsicHeight: + view.layoutIfNeeded() + let targetSize = CGSize(width: (presentingViewController?.view.bounds ?? UIScreen.main.bounds).width, + height: UIView.layoutFittingCompressedSize.height) + let intrinsicHeight = view.systemLayoutSizeFitting(targetSize).height + return bottomYPos - (intrinsicHeight + bottomLayoutOffset) } } diff --git a/Sample/View Controllers/User Groups (Stacked)/StackedProfileViewController.swift b/Sample/View Controllers/User Groups (Stacked)/StackedProfileViewController.swift index 564aa01..6b2e389 100644 --- a/Sample/View Controllers/User Groups (Stacked)/StackedProfileViewController.swift +++ b/Sample/View Controllers/User Groups (Stacked)/StackedProfileViewController.swift @@ -85,6 +85,7 @@ class StackedProfileViewController: UIViewController, PanModalPresentable { roleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true roleLabel.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 4.0).isActive = true + bottomLayoutGuide.topAnchor.constraint(greaterThanOrEqualTo: roleLabel.bottomAnchor).isActive = true } // MARK: - Pan Modal Presentable @@ -94,7 +95,7 @@ class StackedProfileViewController: UIViewController, PanModalPresentable { } var longFormHeight: PanModalHeight { - return .contentHeight(300) + return .intrinsicHeight } var anchorModalToLongForm: Bool { From 3f3124ae37dde77c9a9a764be23fd00a851e50b2 Mon Sep 17 00:00:00 2001 From: Marco Cancellieri Date: Thu, 14 Mar 2019 21:38:02 +0100 Subject: [PATCH 2/2] pr comment --- PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift index d56a3ef..3c13b2a 100644 --- a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift +++ b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift @@ -92,7 +92,7 @@ extension PanModalPresentable where Self: UIViewController { return bottomYPos - height case .intrinsicHeight: view.layoutIfNeeded() - let targetSize = CGSize(width: (presentingViewController?.view.bounds ?? UIScreen.main.bounds).width, + let targetSize = CGSize(width: (presentedVC?.containerView?.bounds ?? UIScreen.main.bounds).width, height: UIView.layoutFittingCompressedSize.height) let intrinsicHeight = view.systemLayoutSizeFitting(targetSize).height return bottomYPos - (intrinsicHeight + bottomLayoutOffset)