Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CM-1003] Add Elevation type #37

Merged
merged 18 commits into from
Dec 15, 2022
Merged

Conversation

karthikyml
Copy link
Contributor

@karthikyml karthikyml commented Dec 15, 2022

Introduction

Design specifies shadows differently than we do in code on iOS. They often refer to them as “elevations”.

Purpose

Elevation struct encapsulates data as per shadows in design software

Single operation:

func apply(layer: CAlayer, cornerRadius: CGFloat)

Sets shadow properties such as shadowOpacity, shadowColor, shadowOffset, shadowRadius

But shadowPath is only set in the case when useShadowPath is true. (Default is true)

Discussion

Because the implementation of spread requires a shadowPath, we will not be able to implement a shadow with a spread for a view whose shape we do not know. For example, shapes that are not rect or round rect.

Out of Scope

We might need to tweak the proposed spread algorithm i.e. add spread to corner radius as well.

📈 Coverage

Code

Screenshot 2022-12-15 at 12 38 48 PM

@karthikyml karthikyml added the enhancement New feature or request label Dec 15, 2022
@karthikyml karthikyml self-assigned this Dec 15, 2022
@mpospese mpospese linked an issue Dec 15, 2022 that may be closed by this pull request
@mpospese
Copy link
Contributor

@karthikyml This all looked really good but I made several adjustments once I started playing with it:

  1. replace offset: CGSize with xOffset: CGFloat and yOffset: CGFloat to better match Figma / css
  2. adjusted blur to shadowRadius conversion factor after experimentation in Figma + Xcode
  3. adjusted shadowPath logic to include spread in adjusting the shadow's corner radius
  4. clamped blur to be a minimum of 0
  5. clamped opacity to be within 0...1
  6. added an extent computed property that we can use to tell how far from the parent view a shadow spreads
  7. moved Elevation from Components to Foundations folder. This is just a hierarchy of design elements. Shadows are primitives similar to colors and text styles.

@karthikyml karthikyml merged commit aa870bd into main Dec 15, 2022
@karthikyml karthikyml deleted the feature/CM-1003-add-elevation-type branch December 15, 2022 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

Add Elevation shadows
2 participants