feat: Moves flagged views into their own module.
This commit is contained in:
40
Sources/FlaggedViews/FlaggedView.swift
Normal file
40
Sources/FlaggedViews/FlaggedView.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import SharedModels
|
||||
import SwiftUI
|
||||
|
||||
public struct FlaggedView<Label: View>: View {
|
||||
|
||||
@Environment(\.flaggedViewStyle) private var flaggedViewStyle
|
||||
|
||||
let label: () -> Label
|
||||
let flagged: Flagged
|
||||
|
||||
public init(
|
||||
flagged: Flagged,
|
||||
@ViewBuilder label: @escaping () -> Label
|
||||
) {
|
||||
self.label = label
|
||||
self.flagged = flagged
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
flaggedViewStyle.makeBody(
|
||||
configuration: FlaggedViewStyleConfiguration(flagged: flagged, label: .init(label()))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension FlaggedView where Label == Text {
|
||||
public init(_ title: LocalizedStringKey, flagged: Flagged) {
|
||||
self.init(flagged: flagged) { Text(title) }
|
||||
}
|
||||
|
||||
public init<S: StringProtocol>(_ title: S, flagged: Flagged) {
|
||||
self.init(flagged: flagged) { Text(title) }
|
||||
}
|
||||
}
|
||||
|
||||
extension FlaggedView where Label == EmptyView {
|
||||
public init(flagged: Flagged) {
|
||||
self.init(flagged: flagged) { EmptyView() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user