Added blur background support for iPhone and iPad. Slight API changes to avoid race conditions while sharing a presenter.

This commit is contained in:
Gil Eluard
2020-11-30 15:11:08 +01:00
parent b1361ba9ad
commit cc4e5f543c
6 changed files with 84 additions and 32 deletions
@@ -39,6 +39,23 @@ class SlidingModalContainerView: UIView, Themable, NibLoadable {
// MARK: - Properties
private weak var blurView: UIVisualEffectView?
var blurBackground: Bool = false {
didSet {
if blurBackground {
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
blurView.frame = self.dimmingView.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.dimmingView.addSubview(blurView)
self.blurView = blurView
self.dimmingView.backgroundColor = .clear
} else {
self.blurView?.removeFromSuperview()
self.dimmingView.backgroundColor = UIColor.black.withAlphaComponent(Constants.dimmingColorAlpha)
}
}
}
// MARK: Outlets
@IBOutlet private weak var dimmingView: UIView!
@@ -61,6 +78,9 @@ class SlidingModalContainerView: UIView, Themable, NibLoadable {
return -(self.contentViewHeightConstraint.constant + bottomSafeAreaHeight)
}
// used to avoid changing constraint during animations
private var lastBounds: CGRect?
// MARK: Public
var contentViewFrame: CGRect {
@@ -92,12 +112,26 @@ class SlidingModalContainerView: UIView, Themable, NibLoadable {
super.layoutSubviews()
self.contentView.layer.cornerRadius = Constants.cornerRadius
guard lastBounds != nil else {
lastBounds = bounds
return
}
if UIDevice.current.userInterfaceIdiom == .pad && lastBounds != bounds {
lastBounds = bounds
self.contentViewBottomConstraint.constant = (UIScreen.main.bounds.height + self.dismissContentViewBottomConstant) / 2
}
}
// MARK: - Public
func preparePresentAnimation() {
self.contentViewBottomConstraint.constant = 0
if UIDevice.current.userInterfaceIdiom == .pad {
self.contentViewBottomConstraint.constant = (UIScreen.main.bounds.height + self.dismissContentViewBottomConstant) / 2
} else {
self.contentViewBottomConstraint.constant = 0
}
}
func prepareDismissAnimation() {