Skip to content

Add Elevation shadows #36

Closed
Closed
@mpospese

Description

@mpospese

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 property offset: CGSize
    • declare a let property of blur: CGFloat
    • declare a let property of spread: CGFloat
    • declare a let property of color: UIColor
    • declare a let property of opacity: CGFloat
    • declare a let property of useShadowPath: Bool (defaults to true)
  • add a func apply that takes parameters layer: CALayer and cornerRadius: CGFloat that applies the elevation to a layer. This method should not set the shadowPath if useShadowPath == 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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions