Merge pull request #5 from Marcocanc/intrinsic-height

Add Intrinsic Height to PanModalHeight
This commit is contained in:
Tosin Afolabi 2019-03-14 13:44:47 -07:00 committed by GitHub
commit f71fa70302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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: (presentedVC?.containerView?.bounds ?? UIScreen.main.bounds).width,
height: UIView.layoutFittingCompressedSize.height)
let intrinsicHeight = view.systemLayoutSizeFitting(targetSize).height
return bottomYPos - (intrinsicHeight + bottomLayoutOffset)
}
}

View File

@ -89,6 +89,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
@ -98,7 +99,7 @@ class StackedProfileViewController: UIViewController, PanModalPresentable {
}
var longFormHeight: PanModalHeight {
return .contentHeight(300)
return .intrinsicHeight
}
var anchorModalToLongForm: Bool {