Add Intrinsic Height

This commit is contained in:
Marco Cancellieri 2019-03-14 18:03:25 +01:00
parent d9f37de98c
commit 21bcb6f268
3 changed files with 12 additions and 1 deletions

View File

@ -35,4 +35,8 @@ public enum PanModalHeight: Equatable {
*/
case contentHeightIgnoringSafeArea(CGFloat)
/**
Sets the height to be the intrinsic content height
*/
case intrinsicHeight
}

View File

@ -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)
}
}

View File

@ -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 {