Skip to content

Commit

Permalink
Implements text view builder for enumerations in EnumeratedList (#75)
Browse files Browse the repository at this point in the history
* Implements text view builder for enumerations in EnumeratedList

* Splits generic types of description and enumeration views in EnumeratedList
  • Loading branch information
LukasLiebl authored Oct 25, 2024
1 parent 9ac488c commit 0647165
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Sources/UIExtensions/Components/SwiftUI/Pure/EnumeratedList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import SwiftUI

/// Enumerated list of Strings such as for instructions or help usage. Enumeration is
/// shown as `CircledNumber`.
public struct EnumeratedList<TextView: View>: View {
public struct EnumeratedList<EnumerationTextView: View, DescriptionTextView: View>: View {
let items: EnumeratedSequence<[String]>
let horizontalSpacing: CGFloat
let verticalSpacing: CGFloat
let circledNumberStrokeColor: Color
let textView: (String) -> TextView
let textView: (String) -> DescriptionTextView
let enumerationTextView: (String) -> EnumerationTextView

/// Initialises a new EnumeratedList
/// - Parameters:
Expand All @@ -19,17 +20,22 @@ public struct EnumeratedList<TextView: View>: View {
/// - verticalSpacing: The vertical spacing between elements
/// - circledNumberStrokeColor: Stroke colour used around the enumerations
/// - textBuilder: A view builder to modify the shown text on the right hand side for each element.
public init(items: EnumeratedSequence<[String]>,
horizontalSpacing: CGFloat = 12,
verticalSpacing: CGFloat = 16,
circledNumberStrokeColor: Color,
@ViewBuilder
textBuilder: @escaping (String) -> TextView) {
public init(
items: EnumeratedSequence<[String]>,
horizontalSpacing: CGFloat = 12,
verticalSpacing: CGFloat = 16,
circledNumberStrokeColor: Color,
@ViewBuilder
textBuilder: @escaping (String) -> DescriptionTextView,
@ViewBuilder
enumerationTextBuilder: @escaping (String) -> EnumerationTextView
) {
self.items = items
self.horizontalSpacing = horizontalSpacing
self.verticalSpacing = verticalSpacing
self.circledNumberStrokeColor = circledNumberStrokeColor
self.textView = textBuilder
self.enumerationTextView = enumerationTextBuilder
}

public var body: some View {
Expand All @@ -46,7 +52,7 @@ public struct EnumeratedList<TextView: View>: View {
number: index + 1,
length: 24,
strokeContent: circledNumberStrokeColor,
content: { Text("\($0)") })
content: { enumerationTextView("\($0)") })
textView(description)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
Expand All @@ -67,9 +73,9 @@ public struct EnumeratedList<TextView: View>: View {
"Optional: sprinkle with emojis, but use sparingly (:sparkles: for feature additions, :bug: for bug fixes)",
"Thanks ChatGPT"
].enumerated(),
circledNumberStrokeColor: Color.black
) { text in
Text(text)
}
circledNumberStrokeColor: Color.black,
textBuilder: { Text($0) },
enumerationTextBuilder: { Text($0) }
)
}
#endif

0 comments on commit 0647165

Please sign in to comment.