Last active
March 13, 2021 15:11
-
-
Save otaviocc/fb6a67ca824b20eacfba9c116560bf2f to your computer and use it in GitHub Desktop.
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 TitleTextStyle: TextStyle { | |
func makeBody( | |
_ configuration: TextStyleConfiguration | |
) -> some View { | |
configuration.text | |
.font(.title) | |
.fontWeight(.bold) | |
.foregroundColor(.accentColor) | |
} | |
} | |
// ... | |
Text(title) | |
.textStyle(TitleTextStyle()) |
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
protocol TextStyle { | |
associatedtype Body: View | |
func makeBody( | |
_ configuration: TextStyleConfiguration | |
) -> Body | |
} | |
struct TextStyleConfiguration { | |
let text: Text | |
} | |
extension Text { | |
func textStyle<S>( | |
_ style: S | |
) -> some View where S: TextStyle { | |
let configuration = TextStyleConfiguration( | |
text: self | |
) | |
return style.makeBody(configuration) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment