WatchConfigRootView.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import SwiftUI
  2. import Swinject
  3. extension WatchConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. var body: some View {
  8. Form {
  9. Section(header: Text("Apple Watch")) {
  10. Picker(
  11. selection: $state.selectedAwConfig,
  12. label: Text("Display on Watch")
  13. ) {
  14. ForEach(AwConfig.allCases) { v in
  15. Text(v.displayName).tag(v)
  16. }
  17. }
  18. }
  19. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  20. Section(header: Text("Garmin Watch")) {
  21. List {
  22. ForEach(state.devices, id: \.uuid) { device in
  23. Text(device.friendlyName)
  24. }
  25. .onDelete(perform: onDelete)
  26. }
  27. Button("Add devices") {
  28. state.selectGarminDevices()
  29. }
  30. }
  31. }
  32. .onAppear(perform: configureView)
  33. .navigationTitle("Watch Configuration")
  34. .navigationBarTitleDisplayMode(.automatic)
  35. }
  36. private func onDelete(offsets: IndexSet) {
  37. state.devices.remove(atOffsets: offsets)
  38. state.deleteGarminDevice()
  39. }
  40. }
  41. }