-
Notifications
You must be signed in to change notification settings - Fork 5
/
RadioButton.swift
48 lines (40 loc) · 1.01 KB
/
RadioButton.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
//
// RadioButton.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//
import Foundation
import SwiftUI
public struct RadioButton: View {
@Binding var isSelected: Bool
public init(isSelected: Binding<Bool>) {
_isSelected = isSelected
}
public var body: some View {
Circle()
.strokeBorder(controlColor, lineWidth: lineWidth)
.frame(width: 24, height: 24)
.animation(.misticaTimingCurve, value: isSelected)
.onTapGesture {
isSelected.toggle()
}
}
var controlColor: Color {
isSelected ? .controlActivated : .control
}
var lineWidth: CGFloat {
isSelected ? 6 : 2
}
}
#if DEBUG
struct RadioButton_Previews: PreviewProvider {
static var previews: some View {
VStack {
RadioButton(isSelected: .constant(true))
RadioButton(isSelected: .constant(false))
}
}
}
#endif