Skip to content

Commit 320f382

Browse files
committed
Add liquid glass BoxView and fix Swift 6 concurrency
1 parent 3a5c81a commit 320f382

3 files changed

Lines changed: 51 additions & 40 deletions

File tree

‎Sources/BlocKit/Extensions/Text.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct OffsetText<S>: View where S: StringProtocol {
6565
}
6666
}
6767

68-
struct CustomFont {
68+
struct CustomFont: Sendable {
6969
var type: FontType
7070
var weight: FontWeight
7171
var style: UIFont.TextStyle

‎Sources/BlocKit/Extensions/View+CustomFont.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public extension Font {
3535
}
3636
#endif
3737

38-
public enum FontType: String {
38+
public enum FontType: String, Sendable {
3939
case montserrat
4040
case josefinSans
4141
case poppins
@@ -47,7 +47,7 @@ public enum FontType: String {
4747
}
4848
}
4949

50-
public enum FontWeight: String {
50+
public enum FontWeight: String, Sendable {
5151
case light
5252
case medium
5353
case semiBold

‎Sources/BlocKit/Views/BoxView.swift‎

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,85 @@
66
//
77

88
import SwiftUI
9-
import UIKit
109

11-
public enum BoxHeaderType: String {
10+
public enum BoxHeaderType: String, Sendable {
1211
case target
1312
case yours
13+
14+
public var localizedString: LocalizedStringKey {
15+
switch self {
16+
case .target: return "Target"
17+
case .yours: return "Yours"
18+
}
19+
}
1420
}
1521

1622
public struct BoxView<Content: View, Fill: ShapeStyle>: View {
1723
let header: BoxHeaderType
1824
let fill: Fill
1925
let content: Content
20-
26+
2127
public init(_ header: BoxHeaderType, _ fill: Fill, @ViewBuilder _ content: () -> Content) {
2228
self.header = header
2329
self.fill = fill
2430
self.content = content()
2531
}
26-
32+
2733
public var body: some View {
2834
ZStack(alignment: .top) {
29-
RoundedRectangle(cornerRadius: Constants.cornerRadius)
35+
RoundedRectangle(cornerRadius: 16)
3036
.fill(fill)
31-
.overlay(RoundedRectangle(cornerRadius: Constants.cornerRadius)
32-
.stroke(Color.stroke))
33-
37+
3438
VStack {
35-
Text(header.rawValue.lowercased())
36-
.blurredBackgroundText()
39+
Text(header.localizedString)
40+
.modifier(GlassHeaderViewModifier())
3741

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))
4342
content
4443
}
4544
}
4645
.padding(.bottom, 4)
4746
}
4847
}
4948

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+
}
5464
}
5565

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
6668

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)
6778
}
6879
}
6980

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)
7887
}
88+
.padding()
89+
.preferredColorScheme(.light)
7990
}

0 commit comments

Comments
 (0)