Added the ability to select a color for the background of the pan modal container (#54)

This commit is contained in:
Nikita Nikitsky 2019-10-02 02:53:39 +04:00 committed by Stephen Sowole
parent 9134d20032
commit 6b1edd1dfb
7 changed files with 17 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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