Created
July 10, 2025 15:47
-
-
Save KlemensStrasser/3823b8b7ff4aa556c5d25c3f463525aa to your computer and use it in GitHub Desktop.
TextDesignModifier
This file contains hidden or 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 TextDesignModifier: ViewModifier { | |
| typealias SizeDefinition = FontName.SizeDefinition | |
| var sizeDefinition: SizeDefinition | |
| var fontName: FontName? | |
| /// This is here to force a non-accessible font if needed (i.e. in the Font picker) | |
| var makeNameAccessibilitySafe: Bool | |
| @AppStorage(\.fontName, storeType: .shared) var currentFont | |
| init(sizeDefinition: SizeDefinition, fontName: FontName? = nil, makeNameAccessibilitySafe: Bool = true) { | |
| self.sizeDefinition = sizeDefinition | |
| self.fontName = fontName | |
| self.makeNameAccessibilitySafe = makeNameAccessibilitySafe | |
| } | |
| func body(content: Content) -> some View { | |
| let effectiveFontName: FontName | |
| if let fontName, fontName.isAccessibilityFont || makeNameAccessibilitySafe == false || currentFont.isAccessibilityFont == false { | |
| effectiveFontName = fontName | |
| } else { | |
| effectiveFontName = currentFont | |
| } | |
| return content | |
| .font(effectiveFontName.generateFont(sizeDefinition: sizeDefinition)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment