@@ -56,10 +56,10 @@ import SwiftUI
56
56
public struct DynamicText : Equatable , Hashable , Identifiable {
57
57
public var id : DynamicElementIdentifier
58
58
59
- fileprivate let storage : Storage
60
- fileprivate var modifiers : [ Modifier ] = [ ]
59
+ public let storage : Storage
60
+ public var modifiers : [ Modifier ] = [ ]
61
61
62
- fileprivate init (
62
+ public init (
63
63
storage: Storage ,
64
64
modifiers: [ Modifier ] = [ ]
65
65
) {
@@ -68,7 +68,7 @@ public struct DynamicText: Equatable, Hashable, Identifiable {
68
68
self . id = . uuid( )
69
69
}
70
70
71
- fileprivate enum Modifier : Equatable , Hashable {
71
+ public enum Modifier : Equatable , Hashable {
72
72
case accessibilityHeading( AccessibilityHeadingLevel )
73
73
case accessibilityLabel( DynamicText )
74
74
case accessibilityTextContentType( AccessibilityTextContentType )
@@ -84,12 +84,12 @@ public struct DynamicText: Equatable, Hashable, Identifiable {
84
84
case underline( active: Bool , color: Color ? )
85
85
}
86
86
87
- fileprivate enum Storage : Equatable , Hashable {
87
+ public enum Storage : Equatable , Hashable {
88
88
indirect case concatenated( DynamicText , DynamicText )
89
89
case localized( LocalizedStringKey , tableName: String ? , bundle: Bundle ? , comment: StaticString ? )
90
90
case verbatim( String )
91
91
92
- static func == ( lhs: Self , rhs: Self ) -> Bool {
92
+ public static func == ( lhs: Self , rhs: Self ) -> Bool {
93
93
switch ( lhs, rhs) {
94
94
case let ( . concatenated( l1, l2) , . concatenated( r1, r2) ) :
95
95
return l1 == r1 && l2 == r2
@@ -111,7 +111,7 @@ public struct DynamicText: Equatable, Hashable, Identifiable {
111
111
}
112
112
}
113
113
114
- func hash( into hasher: inout Hasher ) {
114
+ public func hash( into hasher: inout Hasher ) {
115
115
enum Key {
116
116
case concatenated
117
117
case localized
@@ -225,41 +225,10 @@ extension DynamicText {
225
225
extension DynamicText {
226
226
public enum AccessibilityTextContentType : String , Equatable , Hashable {
227
227
case console, fileSystem, messaging, narrative, plain, sourceCode, spreadsheet, wordProcessing
228
-
229
- #if compiler(>=5.5.1)
230
- @available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
231
- var toSwiftUI : SwiftUI . AccessibilityTextContentType {
232
- switch self {
233
- case . console: return . console
234
- case . fileSystem: return . fileSystem
235
- case . messaging: return . messaging
236
- case . narrative: return . narrative
237
- case . plain: return . plain
238
- case . sourceCode: return . sourceCode
239
- case . spreadsheet: return . spreadsheet
240
- case . wordProcessing: return . wordProcessing
241
- }
242
- }
243
- #endif
244
228
}
245
229
246
230
public enum AccessibilityHeadingLevel : String , Equatable , Hashable {
247
231
case h1, h2, h3, h4, h5, h6, unspecified
248
-
249
- #if compiler(>=5.5.1)
250
- @available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
251
- var toSwiftUI : SwiftUI . AccessibilityHeadingLevel {
252
- switch self {
253
- case . h1: return . h1
254
- case . h2: return . h2
255
- case . h3: return . h3
256
- case . h4: return . h4
257
- case . h5: return . h5
258
- case . h6: return . h6
259
- case . unspecified: return . unspecified
260
- }
261
- }
262
- #endif
263
232
}
264
233
}
265
234
@@ -300,84 +269,6 @@ extension DynamicText {
300
269
}
301
270
}
302
271
303
- extension Text {
304
- public init ( _ state: DynamicText ) {
305
- let text : Text
306
- switch state. storage {
307
- case let . concatenated( first, second) :
308
- text = Text ( first) + Text( second)
309
- case let . localized( content, tableName, bundle, comment) :
310
- text = . init( content, tableName: tableName, bundle: bundle, comment: comment)
311
- case let . verbatim( content) :
312
- text = . init( verbatim: content)
313
- }
314
- self = state. modifiers. reduce ( text) { text, modifier in
315
- switch modifier {
316
- #if compiler(>=5.5.1)
317
- case let . accessibilityHeading( level) :
318
- if #available( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * ) {
319
- return text. accessibilityHeading ( level. toSwiftUI)
320
- } else {
321
- return text
322
- }
323
- case let . accessibilityLabel( value) :
324
- if #available( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * ) {
325
- switch value. storage {
326
- case let . verbatim( string) :
327
- return text. accessibilityLabel ( string)
328
- case let . localized( key, tableName, bundle, comment) :
329
- return text. accessibilityLabel (
330
- Text ( key, tableName: tableName, bundle: bundle, comment: comment) )
331
- case . concatenated( _, _) :
332
- assertionFailure ( " `.accessibilityLabel` does not support contcatenated `DynamicText` " )
333
- return text
334
- }
335
- } else {
336
- return text
337
- }
338
- case let . accessibilityTextContentType( type) :
339
- if #available( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * ) {
340
- return text. accessibilityTextContentType ( type. toSwiftUI)
341
- } else {
342
- return text
343
- }
344
- #else
345
- case . accessibilityHeading,
346
- . accessibilityLabel,
347
- . accessibilityTextContentType:
348
- return text
349
- #endif
350
- case let . baselineOffset( baselineOffset) :
351
- return text. baselineOffset ( baselineOffset)
352
- case . bold:
353
- return text. bold ( )
354
- case let . font( font) :
355
- return text. font ( font)
356
- case let . fontWeight( weight) :
357
- return text. fontWeight ( weight)
358
- case let . foregroundColor( color) :
359
- return text. foregroundColor ( color)
360
- case . italic:
361
- return text. italic ( )
362
- case let . kerning( kerning) :
363
- return text. kerning ( kerning)
364
- case let . strikethrough( active, color) :
365
- return text. strikethrough ( active, color: color)
366
- case let . tracking( tracking) :
367
- return text. tracking ( tracking)
368
- case let . underline( active, color) :
369
- return text. underline ( active, color: color)
370
- }
371
- }
372
- }
373
- }
374
-
375
- extension DynamicText : View {
376
- public var body : some View {
377
- Text ( self )
378
- }
379
- }
380
-
381
272
extension String {
382
273
public init ( state: DynamicText , locale: Locale ? = nil ) {
383
274
switch state. storage {
0 commit comments