2022-01-08 00:36:18 +05:30
|
|
|
import Defaults
|
2021-07-22 18:13:13 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct DetailBadge: View {
|
|
|
|
enum Style {
|
|
|
|
case `default`, prominent, outstanding, informational
|
|
|
|
}
|
|
|
|
|
|
|
|
struct StyleModifier: ViewModifier {
|
|
|
|
let style: Style
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
Group {
|
|
|
|
switch style {
|
|
|
|
case .prominent:
|
|
|
|
content.modifier(ProminentStyleModifier())
|
|
|
|
case .outstanding:
|
|
|
|
content.modifier(OutstandingStyleModifier())
|
|
|
|
case .informational:
|
|
|
|
content.modifier(InformationalStyleModifier())
|
|
|
|
default:
|
|
|
|
content.modifier(DefaultStyleModifier())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DefaultStyleModifier: ViewModifier {
|
2021-12-05 22:39:25 +05:30
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
2021-07-22 18:13:13 +05:30
|
|
|
func body(content: Content) -> some View {
|
2021-11-28 20:07:55 +05:30
|
|
|
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
|
|
|
content
|
|
|
|
.background(.thinMaterial)
|
|
|
|
} else {
|
|
|
|
content
|
2022-01-06 20:28:16 +05:30
|
|
|
#if os(macOS)
|
2022-01-06 21:30:58 +05:30
|
|
|
.background(VisualEffectBlur(material: .hudWindow))
|
2022-01-06 20:28:16 +05:30
|
|
|
#elseif os(iOS)
|
|
|
|
.background(VisualEffectBlur(blurStyle: .systemThinMaterial))
|
2021-12-05 22:39:25 +05:30
|
|
|
#endif
|
2021-11-28 20:07:55 +05:30
|
|
|
}
|
2021-07-22 18:13:13 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ProminentStyleModifier: ViewModifier {
|
|
|
|
var font: Font {
|
|
|
|
Font.system(.body).weight(.semibold)
|
|
|
|
}
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
|
|
|
.font(font)
|
|
|
|
.modifier(DefaultStyleModifier())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct OutstandingStyleModifier: ViewModifier {
|
|
|
|
var backgroundColor: Color {
|
|
|
|
Color("DetailBadgeOutstandingStyleBackgroundColor")
|
|
|
|
}
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
|
|
|
.textCase(.uppercase)
|
|
|
|
.background(backgroundColor)
|
|
|
|
.foregroundColor(.white)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InformationalStyleModifier: ViewModifier {
|
|
|
|
var backgroundColor: Color {
|
|
|
|
Color("DetailBadgeInformationalStyleBackgroundColor")
|
|
|
|
}
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
|
|
|
.background(backgroundColor)
|
|
|
|
.foregroundColor(.white)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var text: String
|
|
|
|
var style: Style = .default
|
|
|
|
|
2022-01-08 00:36:18 +05:30
|
|
|
@Default(.roundedThumbnails) private var roundedThumbnails
|
|
|
|
|
2021-07-22 18:13:13 +05:30
|
|
|
var body: some View {
|
|
|
|
Text(text)
|
|
|
|
.truncationMode(.middle)
|
2022-01-08 00:36:18 +05:30
|
|
|
.padding(4)
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 5)
|
|
|
|
#endif
|
2021-07-22 18:13:13 +05:30
|
|
|
.modifier(StyleModifier(style: style))
|
2022-01-08 00:36:18 +05:30
|
|
|
.mask(RoundedRectangle(cornerRadius: roundedThumbnails ? 6 : 0))
|
2021-07-22 18:13:13 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DetailBadge_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
|
|
|
DetailBadge(text: "Live", style: .outstanding)
|
|
|
|
DetailBadge(text: "Premieres", style: .informational)
|
|
|
|
DetailBadge(text: "Booyah", style: .prominent)
|
|
|
|
DetailBadge(
|
|
|
|
text: "Donec in neque mi. Phasellus quis sapien metus. Ut felis ante, posuere."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.frame(maxWidth: 500)
|
|
|
|
}
|
|
|
|
}
|