Created
September 9, 2019 23:03
-
-
Save vince19972/d0b132129a2f57b3588bfb942dabfe63 to your computer and use it in GitHub Desktop.
Demo code of extending color and font in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TokenColor { | |
// --snip-- | |
// see here for more: https://gist.github.com/vince19972/70eee7d66735739aa31567efd7a0a475 | |
} | |
struct TokenTypography { | |
// --snip-- | |
// see here for more: https://gist.github.com/vince19972/8ff8635bdb7bfdf54b85ab711b55f634l | |
} | |
// extend from native `Color` and `Font` struct | |
extension Color { | |
static let Token = TokenColor() | |
} | |
extension Font { | |
static let Typography = TokenTypography() | |
} | |
// use the tokens | |
struct ContentView: View { | |
Text("Demo of extension") | |
.font(Font.Typography.mainFont) | |
.foregroundColor(Color.Token.textTheme) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment