41 lines
926 B
Swift
41 lines
926 B
Swift
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() }
|
|
}
|
|
}
|