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

Feature: Text style #31

Merged
merged 6 commits into from
Nov 8, 2024
Merged

Feature: Text style #31

merged 6 commits into from
Nov 8, 2024

Conversation

prochazkafilip
Copy link
Contributor

Overview:
This pull request adds a new structure, TextStyle, to the codebase, which provides a comprehensive way to define and apply text styles in SwiftUI applications. The TextStyle structure allows developers to specify various attributes such as font type, size, line height, font scaling, letter spacing, text case, and text decoration. The primary goal of this enhancement is to simplify the process of translating text styles from Figma designs into SwiftUI, ensuring consistency and ease of use.

Usage:
Developers can apply the text style to views using the textStyle(_:) modifier or specifically to Text views with the textStyleText(_:) modifier. The stylize(with:) method allows applying the text style to attributed strings, and an initializer for NSAttributedString simplifies the creation of attributed strings with the specified text style.

Example:

extension TextStyle {
    static let title = TextStyle(
        fontType: .system(weight: .bold),
        size: 24,
        lineHeight: 32,
        scaling: .relativeTo(textStyle: .title),
        letter: .relative(percent: 5),
        textCase: .uppercase,
        textDecoration: .underline
    )
}

struct ExampleView: View {
    var body: some View {
        Text("Title")
            .textStyle(.title)
    }
}

Notes:

The textStyleText(_:) modifier and the stylize(with:) method do not apply line spacing, text case, or vertical padding based on line height.
This enhancement aims to streamline the integration of text styles from Figma designs into the SwiftUI framework, improving code maintainability and visual consistency across the application.

samoilyk
samoilyk previously approved these changes Nov 7, 2024
@prochazkafilip prochazkafilip merged commit bc19b1b into main Nov 8, 2024
1 check passed
@prochazkafilip prochazkafilip deleted the feature/text-style branch November 8, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants