-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpandablePickerView.swift
54 lines (50 loc) · 1.59 KB
/
ExpandablePickerView.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
//
// ExpandablePickerView.swift
// Lucify (iOS)
//
// Created by Patrick Elfert on 03.07.22.
//
import SwiftUI
struct ExpandablePickerView<Content: View>: View {
var systemName: String
var title: String
var footNote: String
@Binding var enabled: Bool
@ViewBuilder var content: Content
@State var isClicked: Bool = false
var body: some View {
Toggle(isOn: Binding(get: { enabled }, set: { enabled = $0; if $0 == true { isClicked = false }})) {
Image(systemName: systemName).foregroundColor(Primary)
HStack {
VStack(alignment: .leading) {
Text("Chaining")
if enabled {
Text(footNote)
.font(.footnote)
.padding(.leading, 2)
.foregroundColor(Primary)
}
}
Spacer()
}.onTapGesture {
withAnimation(.easeInOut) {
isClicked.toggle()
}
}
}.tint(Primary)
if enabled && isClicked {
content
}
}
}
struct ExpandablePickerView_Previews: PreviewProvider {
static var previews: some View {
ExpandablePickerView(systemName: "repeat.circle.fill", title: "Chaining", footNote: "4 times", enabled: .constant(true)) {
Picker("Number of alarms", selection: .constant(2)) {
Text("2").tag(2)
Text("4").tag(4)
Text("6").tag(6)
}.pickerStyle(.segmented)
}
}
}