Closed
Description
Intro
Design specifies shadows differently than we do in code on iOS. They often refer to them as “elevations”. Let’s add a struct to encapsulate design shadows and apply them to views.
Tasks
- declare a public struct Elevation
- declare a
let
propertyoffset: CGSize
- declare a
let
property ofblur: CGFloat
- declare a
let
property ofspread: CGFloat
- declare a
let
property ofcolor: UIColor
- declare a
let
property ofopacity: CGFloat
- declare a
let
property ofuseShadowPath: Bool
(defaults to true)
- declare a
- add a func
apply
that takes parameterslayer: CALayer
andcornerRadius: CGFloat
that applies the elevation to a layer. This method should not set the shadowPath ifuseShadowPath == false
.
pseudo code:
struct Elevation {
let offset: CGSize
let blur: CGFloat
let spread: CGFloat
let color: UIColor
let opacity: CGFloat
let useShadowPath: Bool // defaults to `true`
func apply(layer: CALayer, cornerRadius: CGFloat) {
layer.shadowColor = color.cgColor
layer.shadowOffset = offset
layer.shadowOpacity = opacity
layer.shadowRadius = blur / 2
guard useShadowPath else { return }
let rect = layer.bounds.insetBy(dx: -spread, dy: -spread)
layer.shadowPath = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius).cgPath
}
}
Discussion
Because the implementation of spread
requires a shadow path, we will not be able to implement a shadow with spread for a view whose shape we do not know (e.g. useShadowPath == false
).
Acceptance Criteria
- Implement
Elevation
as described in Tasks above - SwiftLint analysis has 0 violations
- fully unit test the new code
- fully document all public interfaces on the new code (as per Jazzy documentation coverage tests)
Metadata
Metadata
Assignees
Labels
No labels