Skip to main content

Blink/Views/Thumbnails/ReviewStateBorder.swift

1import SwiftUI
3import SwiftUI
5/// Renders a small icon to show the review state, e.g. a green circled tick
6/// for "Approved" images.
7struct ReviewStateBorder: ViewModifier {
8 let state: ReviewState?
9 let cornerRadius: CGFloat
11 init(_ state: ReviewState?, _ cornerRadius: CGFloat) {
12 self.state = state
13 self.cornerRadius = cornerRadius
14 }
16 func body(content: Content) -> some View {
17 content.overlay() {
18 // This technique for drawing a coloured border with rounded corners
19 // comes from an article by Simon Ng:
20 // https://www.appcoda.com/swiftui-border/
21 RoundedRectangle(cornerRadius: cornerRadius)
22 .stroke(
23 state?.color() ?? .gray.opacity(0.7),
24 lineWidth: state != nil ? 3.0 : 3.0 * 5.0 / 7.0
25 )
26 }
27 }
30extension View {
31 func reviewStateBorder(for state: ReviewState?, with cornerRadius: CGFloat) -> some View {
32 modifier(ReviewStateBorder(state, cornerRadius))
33 }