88
99import SwiftUI
1010
11+ /// A singe line text label that supports `Typography` for SwiftUI.
1112public struct TextStyleLabel : View {
12- private let text : String
13- private let typography : Typography
14- private let configureTypographyText : ( ( TypographyLabel ) -> Void ) ?
13+ /// The text that the label displays.
14+ let text : String
15+
16+ /// Typography to be used for this label's text
17+ let typography : Typography
18+
19+ /// A closure that gets called on the init and refresh of the View
20+ /// This closure allows you to provide additional configuration to the `TypographyLabel`
21+ let configureTextStyleLabel : ( ( TypographyLabel ) -> Void ) ?
1522
16- public init ( _ text: String ,
17- typography: Typography ,
18- configuration: ( ( TypographyLabel ) -> Void ) ? = nil ) {
19- self . typography = typography
20- self . text = text
21- self . configureTypographyText = configuration
23+ /// The content and behavior of the view.
24+ public var body : some View {
25+ TypographyLabelRepresentable (
26+ text: text,
27+ typography: typography,
28+ configureTextStyleLabel: configureTextStyleLabel
29+ )
30+ . fixedSize ( horizontal: false , vertical: true )
2231 }
2332
24- public var body : some View {
25- TypographyLabelRepresentable ( text,
26- typography: typography,
27- configuration: configureTypographyText)
28- . fixedSize ( horizontal: false , vertical: true )
33+ /// Initializes a `TextStyleLabel` instance with the specified parameters
34+ /// - Parameters:
35+ /// - text: The text that the label displays
36+ /// - typography: Typography to be used for this label's text
37+ /// - configuration: A closure that gets called on the init and refresh of the View
38+ public init (
39+ _ text: String ,
40+ typography: Typography ,
41+ configuration: ( ( TypographyLabel ) -> Void ) ? = nil
42+ ) {
43+ self . typography = typography
44+ self . text = text
45+ self . configureTextStyleLabel = configuration
2946 }
3047}
3148
32- public extension TextStyleLabel {
49+ extension TextStyleLabel {
50+ /// A wrapper for a UIKit TypographyLabel view that allows to integrate that view into a SwiftUI view hierarchy.
3351 struct TypographyLabelRepresentable : UIViewRepresentable {
34- public typealias UIViewType = TypographyLabel
35-
36- private let typography : Typography
37- private let text : String
38- private let configureText : ( ( TypographyLabel ) -> Void ) ?
52+ /// The type of view to present.
53+ typealias UIViewType = TypographyLabel
3954
40- public init ( _ text: String ,
41- typography: Typography ,
42- configuration: ( ( TypographyLabel ) -> Void ) ? = nil ) {
43- self . typography = typography
44- self . text = text
45- self . configureText = configuration
46- }
55+ /// The text that the label displays.
56+ let text : String
4757
48- public func makeUIView( context: Context ) -> TypographyLabel {
58+ /// Typography to be used for this label's text
59+ let typography : Typography
60+
61+ /// A closure that gets called on the init and refresh of the View
62+ let configureTextStyleLabel : ( ( TypographyLabel ) -> Void ) ?
63+
64+ /// Creates the view object and configures its initial state.
65+ ///
66+ /// - Parameter context: A context structure containing information about
67+ /// the current state of the system.
68+ ///
69+ /// - Returns: `TypographyLabel` view configured with the provided information.
70+ func makeUIView( context: Context ) -> TypographyLabel {
4971 let label = TypographyLabel ( typography: typography)
5072 label. text = text
5173
@@ -54,14 +76,21 @@ public extension TextStyleLabel {
5476 label. setContentCompressionResistancePriority ( . defaultLow, for: . horizontal)
5577 label. setContentCompressionResistancePriority ( . defaultLow, for: . vertical)
5678
57- configureText ? ( label)
79+ configureTextStyleLabel ? ( label)
5880 return label
5981 }
6082
61- public func updateUIView( _ uiView: TypographyLabel , context: Context ) {
83+ /// Updates the state of the specified view with new information from
84+ /// SwiftUI.
85+ ///
86+ /// - Parameters:
87+ /// - uiView: `TypographyLabel` view.
88+ /// - context: A context structure containing information about the current
89+ /// state of the system.
90+ func updateUIView( _ uiView: TypographyLabel , context: Context ) {
6291 uiView. typography = typography
6392 uiView. text = text
64- configureText ? ( uiView)
93+ configureTextStyleLabel ? ( uiView)
6594 }
6695 }
6796}
0 commit comments