Added the ability to select a color for the background of the pan modal container (#54)
This commit is contained in:
parent
9134d20032
commit
6b1edd1dfb
|
|
@ -105,8 +105,8 @@ public class PanModalPresentationController: UIPresentationController {
|
|||
*/
|
||||
private lazy var backgroundView: DimmedView = {
|
||||
let view: DimmedView
|
||||
if let alpha = presentable?.backgroundAlpha {
|
||||
view = DimmedView(dimAlpha: alpha)
|
||||
if let color = presentable?.panModalBackgroundColor {
|
||||
view = DimmedView(dimColor: color)
|
||||
} else {
|
||||
view = DimmedView()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ public extension PanModalPresentable where Self: UIViewController {
|
|||
return [.curveEaseInOut, .allowUserInteraction, .beginFromCurrentState]
|
||||
}
|
||||
|
||||
var backgroundAlpha: CGFloat {
|
||||
return 0.7
|
||||
var panModalBackgroundColor: UIColor {
|
||||
return UIColor.black.withAlphaComponent(0.7)
|
||||
}
|
||||
|
||||
var scrollIndicatorInsets: UIEdgeInsets {
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@ public protocol PanModalPresentable: AnyObject {
|
|||
var transitionAnimationOptions: UIView.AnimationOptions { get }
|
||||
|
||||
/**
|
||||
The background view alpha.
|
||||
The background view color.
|
||||
|
||||
- Note: This is only utilized at the very start of the transition.
|
||||
|
||||
Default Value is 0.7.
|
||||
*/
|
||||
var backgroundAlpha: CGFloat { get }
|
||||
Default Value is black with alpha component 0.7.
|
||||
*/
|
||||
var panModalBackgroundColor: UIColor { get }
|
||||
|
||||
/**
|
||||
We configure the panScrollable's scrollIndicatorInsets interally so override this value
|
||||
|
|
|
|||
|
|
@ -31,12 +31,11 @@ public class DimmedView: UIView {
|
|||
didSet {
|
||||
switch dimState {
|
||||
case .max:
|
||||
alpha = dimAlpha
|
||||
alpha = 1.0
|
||||
case .off:
|
||||
alpha = 0.0
|
||||
case .percent(let percentage):
|
||||
let val = max(0.0, min(1.0, percentage))
|
||||
alpha = dimAlpha * val
|
||||
alpha = max(0.0, min(1.0, percentage))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,15 +52,12 @@ public class DimmedView: UIView {
|
|||
return UITapGestureRecognizer(target: self, action: #selector(didTapView))
|
||||
}()
|
||||
|
||||
private let dimAlpha: CGFloat
|
||||
|
||||
// MARK: - Initializers
|
||||
|
||||
init(dimAlpha: CGFloat = 0.7) {
|
||||
self.dimAlpha = dimAlpha
|
||||
init(dimColor: UIColor = UIColor.black.withAlphaComponent(0.7)) {
|
||||
super.init(frame: .zero)
|
||||
alpha = 0.0
|
||||
backgroundColor = .black
|
||||
backgroundColor = dimColor
|
||||
addGestureRecognizer(tapGesture)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ class TransientAlertViewController: AlertViewController {
|
|||
return true
|
||||
}
|
||||
|
||||
override var backgroundAlpha: CGFloat {
|
||||
return 0.0
|
||||
override var panModalBackgroundColor: UIColor {
|
||||
return .clear
|
||||
}
|
||||
|
||||
override var isUserInteractionEnabled: Bool {
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ class AlertViewController: UIViewController, PanModalPresentable {
|
|||
return shortFormHeight
|
||||
}
|
||||
|
||||
var backgroundAlpha: CGFloat {
|
||||
return 0.1
|
||||
var panModalBackgroundColor: UIColor {
|
||||
return UIColor.black.withAlphaComponent(0.1)
|
||||
}
|
||||
|
||||
var shouldRoundTopCorners: Bool {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class PanModalTests: XCTestCase {
|
|||
XCTAssertEqual(vc.shortFormHeight, PanModalHeight.maxHeight)
|
||||
XCTAssertEqual(vc.longFormHeight, PanModalHeight.maxHeight)
|
||||
XCTAssertEqual(vc.springDamping, 0.8)
|
||||
XCTAssertEqual(vc.backgroundAlpha, 0.7)
|
||||
XCTAssertEqual(vc.panModalBackgroundColor, UIColor.black.withAlphaComponent(0.7))
|
||||
XCTAssertEqual(vc.scrollIndicatorInsets, .zero)
|
||||
XCTAssertEqual(vc.anchorModalToLongForm, true)
|
||||
XCTAssertEqual(vc.allowsExtendedPanScrolling, false)
|
||||
|
|
|
|||
Loading…
Reference in New Issue