|
6 | 6 | // |
7 | 7 |
|
8 | 8 | import SwiftUI |
9 | | -import UIKit |
10 | 9 |
|
11 | | -public enum BoxHeaderType: String { |
| 10 | +public enum BoxHeaderType: String, Sendable { |
12 | 11 | case target |
13 | 12 | case yours |
| 13 | + |
| 14 | + public var localizedString: LocalizedStringKey { |
| 15 | + switch self { |
| 16 | + case .target: return "Target" |
| 17 | + case .yours: return "Yours" |
| 18 | + } |
| 19 | + } |
14 | 20 | } |
15 | 21 |
|
16 | 22 | public struct BoxView<Content: View, Fill: ShapeStyle>: View { |
17 | 23 | let header: BoxHeaderType |
18 | 24 | let fill: Fill |
19 | 25 | let content: Content |
20 | | - |
| 26 | + |
21 | 27 | public init(_ header: BoxHeaderType, _ fill: Fill, @ViewBuilder _ content: () -> Content) { |
22 | 28 | self.header = header |
23 | 29 | self.fill = fill |
24 | 30 | self.content = content() |
25 | 31 | } |
26 | | - |
| 32 | + |
27 | 33 | public var body: some View { |
28 | 34 | ZStack(alignment: .top) { |
29 | | - RoundedRectangle(cornerRadius: Constants.cornerRadius) |
| 35 | + RoundedRectangle(cornerRadius: 16) |
30 | 36 | .fill(fill) |
31 | | - .overlay(RoundedRectangle(cornerRadius: Constants.cornerRadius) |
32 | | - .stroke(Color.stroke)) |
33 | | - |
| 37 | + |
34 | 38 | VStack { |
35 | | - Text(header.rawValue.lowercased()) |
36 | | - .blurredBackgroundText() |
| 39 | + Text(header.localizedString) |
| 40 | + .modifier(GlassHeaderViewModifier()) |
37 | 41 |
|
38 | | - .padding(8) |
39 | | -// .background( |
40 | | -// NotchRectangle(corner: [.bottomLeft, .bottomRight], size: Constants.cornerRadius / 1.5) |
41 | | -// .fill(Color.white.opacity(0.25)) |
42 | | -// .padding(.top, -1)) |
43 | 42 | content |
44 | 43 | } |
45 | 44 | } |
46 | 45 | .padding(.bottom, 4) |
47 | 46 | } |
48 | 47 | } |
49 | 48 |
|
50 | | -struct VisualEffectView: UIViewRepresentable { |
51 | | - var effect: UIVisualEffect? |
52 | | - func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView { UIVisualEffectView() } |
53 | | - func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) { uiView.effect = effect } |
| 49 | +public struct GlassHeaderViewModifier: ViewModifier { |
| 50 | + public init() {} |
| 51 | + |
| 52 | + public func body(content: Content) -> some View { |
| 53 | + content |
| 54 | + .font(.caption) |
| 55 | + .fontWidth(.expanded) |
| 56 | + .foregroundStyle(.white) |
| 57 | + .accessibility(addTraits: .isHeader) |
| 58 | + .padding(.top, 1) |
| 59 | + .padding(.horizontal) |
| 60 | + .padding(8) |
| 61 | + .glassEffect(.clear.tint(.black.opacity(0.3)), in: .rect(cornerRadius: 8)) |
| 62 | + .padding(8) |
| 63 | + } |
54 | 64 | } |
55 | 65 |
|
56 | | -struct BoxView_Previews: PreviewProvider { |
57 | | - static var previews: some View { |
58 | | - GeometryReader { proxy in |
59 | | - BoxView(.target, .orange, { |
60 | | - Text("HELLO") |
61 | | - }) |
62 | | - .frame(width: proxy.size.width, height: proxy.size.height / 3, alignment: .bottom) |
63 | | - } |
64 | | - .padding() |
65 | | - .preferredColorScheme(.light) |
| 66 | +public struct NavigationBarHeader: View { |
| 67 | + let title: LocalizedStringKey |
66 | 68 |
|
| 69 | + public init(_ title: LocalizedStringKey) { |
| 70 | + self.title = title |
| 71 | + } |
| 72 | + |
| 73 | + public var body: some View { |
| 74 | + Text(title) |
| 75 | + .font(.system(size: 24, weight: .bold, design: .rounded)) |
| 76 | + .fontWidth(.expanded) |
| 77 | + .foregroundColor(.primary) |
67 | 78 | } |
68 | 79 | } |
69 | 80 |
|
70 | | -struct NotchRectangle: Shape { |
71 | | - var corner: UIRectCorner |
72 | | - var size: CGFloat |
73 | | - |
74 | | - func path(in rect: CGRect) -> Path { |
75 | | - let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corner, cornerRadii: CGSize(width: size, height: size)) |
76 | | - |
77 | | - return Path(path.cgPath) |
| 81 | +#Preview { |
| 82 | + GeometryReader { proxy in |
| 83 | + BoxView(.target, .orange, { |
| 84 | + Text("HELLO") |
| 85 | + }) |
| 86 | + .frame(width: proxy.size.width, height: proxy.size.height / 3, alignment: .bottom) |
78 | 87 | } |
| 88 | + .padding() |
| 89 | + .preferredColorScheme(.light) |
79 | 90 | } |
0 commit comments