-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFanOnButton.swift
More file actions
44 lines (40 loc) · 1.32 KB
/
Copy pathFanOnButton.swift
File metadata and controls
44 lines (40 loc) · 1.32 KB
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
import SwiftUI
struct FanOnButton: View {
@ObservedObject var bluetooth: Bluetooth
@State private var timer: Timer?
@State private var longPressEnded = false
init(bluetooth: Bluetooth) {
self.bluetooth = bluetooth
}
var body: some View {
Button(role: .none, action: {
if (self.longPressEnded){
bluetooth.TurnFanOff()
self.longPressEnded = false
}else{
bluetooth.ToggleFan()
}
}, label: {
if let isFanOn = bluetooth.localIsFanOn{
if isFanOn{
Label("", systemImage: "fanblades.fill")
.foregroundColor(.orange)
} else{
Label("", systemImage: "fanblades")
.foregroundColor(.orange)
}
}
})
.simultaneousGesture(LongPressGesture(minimumDuration: 0.175).onEnded { _ in
self.longPressEnded = true
bluetooth.ToggleFan()
})
.font(.title2)
.padding()
}
}
struct FanOnButton_Previews: PreviewProvider {
static var previews: some View {
FanOnButton(bluetooth: Bluetooth.init())
}
}