Add configurable cornerRadius
This commit is contained in:
parent
d9f37de98c
commit
d0b094292f
|
|
@ -36,7 +36,6 @@ public class PanModalPresentationController: UIPresentationController {
|
|||
Constants
|
||||
*/
|
||||
struct Constants {
|
||||
static let cornerRadius = CGFloat(8.0)
|
||||
static let indicatorYOffset = CGFloat(8.0)
|
||||
static let snapMovementSensitivity = CGFloat(0.7)
|
||||
static let dragIndicatorSize = CGSize(width: 36.0, height: 5.0)
|
||||
|
|
@ -797,13 +796,10 @@ private extension PanModalPresentationController {
|
|||
because we render the dragIndicator outside of view bounds
|
||||
*/
|
||||
func addRoundedCorners(to view: UIView) {
|
||||
|
||||
let path = UIBezierPath()
|
||||
path.move(to: CGPoint(x: 0, y: Constants.cornerRadius))
|
||||
|
||||
// 1. Draw left rounded corner
|
||||
path.addArc(withCenter: CGPoint(x: path.currentPoint.x + Constants.cornerRadius, y: path.currentPoint.y),
|
||||
radius: Constants.cornerRadius, startAngle: .pi, endAngle: 3.0 * .pi/2.0, clockwise: true)
|
||||
let radius = presentable?.cornerRadius ?? 0
|
||||
let path = UIBezierPath(roundedRect: view.bounds,
|
||||
byRoundingCorners:[.topRight, .topLeft],
|
||||
cornerRadii: CGSize(width: radius, height: radius))
|
||||
|
||||
// 2. Draw around the drag indicator view, if displayed
|
||||
if presentable?.showDragIndicator == true {
|
||||
|
|
@ -811,17 +807,6 @@ private extension PanModalPresentationController {
|
|||
drawAroundDragIndicator(currentPath: path, indicatorLeftEdgeXPos: indicatorLeftEdgeXPos)
|
||||
}
|
||||
|
||||
// 3. Draw line to right side of presented view, leaving space to draw rounded corner
|
||||
path.addLine(to: CGPoint(x: view.bounds.width - Constants.cornerRadius, y: path.currentPoint.y))
|
||||
|
||||
// 4. Draw right rounded corner
|
||||
path.addArc(withCenter: CGPoint(x: path.currentPoint.x, y: path.currentPoint.y + Constants.cornerRadius),
|
||||
radius: Constants.cornerRadius, startAngle: 3.0 * .pi/2.0, endAngle: 0, clockwise: true)
|
||||
|
||||
// 5. Draw around final edges of view
|
||||
path.addLine(to: CGPoint(x: path.currentPoint.x, y: view.bounds.height))
|
||||
path.addLine(to: CGPoint(x: 0, y: path.currentPoint.y))
|
||||
|
||||
// 6. Set path as a mask to display optional drag indicator view & rounded corners
|
||||
let mask = CAShapeLayer()
|
||||
mask.path = path.cgPath
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public extension PanModalPresentable where Self: UIViewController {
|
|||
}
|
||||
|
||||
var scrollIndicatorInsets: UIEdgeInsets {
|
||||
let top = shouldRoundTopCorners ? PanModalPresentationController.Constants.cornerRadius : 0
|
||||
let top = shouldRoundTopCorners ? cornerRadius : 0
|
||||
return UIEdgeInsets(top: CGFloat(top), left: 0, bottom: bottomLayoutOffset, right: 0)
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +77,10 @@ public extension PanModalPresentable where Self: UIViewController {
|
|||
return isPanModalPresented
|
||||
}
|
||||
|
||||
var cornerRadius: CGFloat {
|
||||
return 8
|
||||
}
|
||||
|
||||
var showDragIndicator: Bool {
|
||||
return shouldRoundTopCorners
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,13 @@ public protocol PanModalPresentable {
|
|||
*/
|
||||
var shouldRoundTopCorners: Bool { get }
|
||||
|
||||
/**
|
||||
The corner radius used when `shouldRoundTopCorners` is enabled.
|
||||
|
||||
Default Value is `8.0`
|
||||
*/
|
||||
var cornerRadius: CGFloat { get }
|
||||
|
||||
/**
|
||||
A flag to determine if a drag indicator should be shown
|
||||
above the pan modal container view.
|
||||
|
|
|
|||
Loading…
Reference in New Issue