blob: 8bcf6d71f3bce1ff82b11874726d642637225ace (
plain)
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
|
//
// MainRoomView.swift
// InfiniSolar WatchKit Extension
//
// Created by Evgeny Zinoviev on 08.08.2021.
//
import SwiftUI
struct RoomView: View {
@ObservedObject var state = RoomState()
var body: some View {
VStack(alignment: .leading) {
Text("Room")
.font(.title2)
.fontWeight(.thin)
Spacer().frame(height: 10)
if self.state.error {
Text("Failed to fetch data from si7021d.")
}
else {
Text("Temperature is ").fontWeight(.thin) + Text(String(self.state.temp) + " °C")
Text("Rel. humidity is ").fontWeight(.thin) + Text(String(self.state.rh) + " %")
}
}
.onAppear() {
self.state.start()
}
.onDisappear() {
self.state.stop()
}
}
}
struct RoomView_Previews: PreviewProvider {
static var previews: some View {
RoomView()
}
}
|