-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #581 from kiwicom/578-text-font-weight
Add `textFontWeight` modifier
- Loading branch information
Showing
2 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
Sources/Orbit/Support/Environment Keys/TextFontWeightKey.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import SwiftUI | ||
|
||
struct TextFontWeightKey: EnvironmentKey { | ||
static let defaultValue: Font.Weight? = nil | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
/// A font weight stored in a view’s environment, used for Orbit text based components. | ||
var textFontWeight: Font.Weight? { | ||
get { self[TextFontWeightKey.self] } | ||
set { self[TextFontWeightKey.self] = newValue } | ||
} | ||
} | ||
|
||
public extension View { | ||
|
||
/// Set the font weight for any text based Orbit component within the view hierarchy. | ||
/// | ||
/// - Parameters: | ||
/// - fontWeight: A font weight that will be used in text based Orbit components. | ||
/// Pass `nil` to ignore environment font weight and to allow the system | ||
/// or the container to provide its own font weight. | ||
/// If a container-specific override doesn’t exist, the `regular` will be used. | ||
@available(iOS, introduced: 13, obsoleted: 16, renamed: "fontWeight") | ||
func textFontWeight(_ fontWeight: Font.Weight?) -> some View { | ||
environment(\.textFontWeight, fontWeight) | ||
} | ||
} |