Skip to content

Instantly share code, notes, and snippets.

@o-nnerb
Created June 24, 2021 22:53
Show Gist options
  • Save o-nnerb/e266b3e1bbd3c934607dd26330b0d6c0 to your computer and use it in GitHub Desktop.
Save o-nnerb/e266b3e1bbd3c934607dd26330b0d6c0 to your computer and use it in GitHub Desktop.
Adaptation of Shadow token to support UIKit and SwiftUI
// UIKit
extension CALayer {
public func setShadow(_ level: Shadow) {
shadowRadius = level.radius
shadowOpacity = level.opacity
shadowColor = level.uiColor.cgFloat
shadowOffset = .init(
width: level.x,
height: level.y
)
}
}
// SwiftUI
#if canImport(SwiftUI)
@available(iOS 13, *)
extension View {
public func shadow(_ level: Shadow) -> some View {
shadow(
color: level.color.opacity(level.opacity),
radius: level.radius,
x: level.x,
y: level.y
)
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment