Skip to content

Commit a9db747

Browse files
committed
Add animating toggles
1 parent 9b1b7dd commit a9db747

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

Example/SettingExample/ControlPanelView.swift

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import Setting
1010
import SwiftUI
1111

1212
struct ControlPanelView: View {
13+
@State var volume = Double(8)
14+
@State var airplane = false
15+
@State var wifi = true
16+
@State var bluetooth = true
17+
1318
var body: some View {
1419
SettingStack {
1520
SettingPage(title: "Control Panel") {
@@ -19,7 +24,7 @@ struct ControlPanelView: View {
1924

2025
SettingGroup(header: "Volume") {
2126
SettingSlider(
22-
value: .constant(8),
27+
value: $volume,
2328
range: 0 ... 10,
2429
minimumImage: Image(systemName: "speaker.fill"),
2530
maximumImage: Image(systemName: "speaker.wave.3.fill")
@@ -30,10 +35,37 @@ struct ControlPanelView: View {
3035
}
3136
}
3237

38+
let a = Binding {
39+
airplane
40+
} set: { newValue in
41+
airplane = newValue
42+
if newValue {
43+
wifi = false
44+
bluetooth = false
45+
}
46+
}
47+
48+
let w = Binding {
49+
wifi
50+
} set: { newValue in
51+
wifi = newValue
52+
if newValue {
53+
airplane = false
54+
}
55+
}
56+
let b = Binding {
57+
bluetooth
58+
} set: { newValue in
59+
bluetooth = newValue
60+
if newValue {
61+
airplane = false
62+
}
63+
}
64+
3365
SettingGroup {
34-
SettingToggle(title: "Airplane Mode", isOn: .constant(false))
35-
SettingToggle(title: "Wi-Fi", isOn: .constant(true))
36-
SettingToggle(title: "Bluetooth", isOn: .constant(true))
66+
SettingToggle(title: "Airplane Mode", isOn: a)
67+
SettingToggle(title: "Wi-Fi", isOn: w)
68+
SettingToggle(title: "Bluetooth", isOn: b)
3769
}
3870
}
3971
}
@@ -80,5 +112,3 @@ struct ControlPanelView: View {
80112
.padding(.horizontal, 16)
81113
}
82114
}
83-
84-

0 commit comments

Comments
 (0)