-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRadiuses+SwiftUI.swift
96 lines (86 loc) · 3.02 KB
/
Radiuses+SwiftUI.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Vitamin iOS
// Apache License 2.0
//
#if arch(x86_64) || arch(arm64)
import SwiftUI
import VitaminCore
@available(iOS 13, *)
struct RadiusesModifier: ViewModifier {
let radius: VitaminRadius
let antialiased: Bool
func body(content: Content) -> some View {
content
.cornerRadius(radius.rawValue, antialiased: antialiased)
}
}
@available(iOS 13, *)
struct BorderRadiusesModifier<S: ShapeStyle>: ViewModifier {
let radius: VitaminRadius
let shapeStyle: S
let lineWidth: CGFloat
func body(content: Content) -> some View {
content
.overlay(
RoundedRectangle(cornerRadius: radius.rawValue)
.stroke(shapeStyle, lineWidth: lineWidth)
)
}
}
@available(iOS 13, *)
struct BorderStyleRadiusesModifier<S: ShapeStyle>: ViewModifier {
let radius: VitaminRadius
let shapeStyle: S
let strokeStyle: StrokeStyle
func body(content: Content) -> some View {
content
.overlay(
RoundedRectangle(cornerRadius: radius.rawValue)
.stroke(shapeStyle, style: strokeStyle)
)
}
}
@available(iOS 13, *)
extension View {
/// Apply a corner radius to the view.
/// - Parameters:
/// - radius: The radius to apply.
/// - antialiased: A Boolean value that indicates whether the rendering system
/// applies smoothing to the edges of the clipping rectangle.
/// - Returns: Return the view.
public func vitaminRadius(_ radius: VitaminRadius, antialiased: Bool = true) -> some View {
modifier(RadiusesModifier(radius: radius, antialiased: antialiased))
}
/// Add an overlay with border and corner radius to the view.
/// - Parameters:
/// - radius: The radius to apply.
/// - content: The color or gradient with which to stroke this border.
/// - lineWidth: The width of the border.
/// - Returns: Return the view.
public func vitaminAddBorderRadius<S: ShapeStyle>(
_ radius: VitaminRadius,
content: S,
lineWidth: CGFloat
) -> some View {
modifier(BorderRadiusesModifier(radius: radius,
shapeStyle: content,
lineWidth: lineWidth))
}
/// Add an overlay with border and corner radius to the view.
/// - Parameters:
/// - radius: The radius to apply.
/// - content: The color or gradient with which to stroke this border.
/// - style: The stroke characteristics --- such as the line's width and
/// whether the stroke is dashed --- that determine how to render the border.
/// - Returns: Return the view.
public func vitaminAddBorderRadius<S: ShapeStyle>(
_ radius: VitaminRadius,
content: S,
style: StrokeStyle
) -> some View {
modifier(BorderStyleRadiusesModifier(radius: radius,
shapeStyle: content,
strokeStyle: style))
}
}
#endif