WatchConfigRootView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import SwiftUI
  2. import Swinject
  3. extension WatchConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color("Background_1"),
  12. Color("Background_1"),
  13. Color("Background_2")
  14. // Color("Background_1")
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. var body: some View {
  27. Form {
  28. Section(header: Text("Apple Watch")) {
  29. Picker(
  30. selection: $state.selectedAwConfig,
  31. label: Text("Display on Watch")
  32. ) {
  33. ForEach(AwConfig.allCases) { v in
  34. Text(v.displayName).tag(v)
  35. }
  36. }
  37. }
  38. Toggle("Display Protein & Fat", isOn: $state.displayFatAndProteinOnWatch)
  39. Section(header: Text("Garmin Watch")) {
  40. List {
  41. ForEach(state.devices, id: \.uuid) { device in
  42. Text(device.friendlyName)
  43. }
  44. .onDelete(perform: onDelete)
  45. }
  46. Button("Add devices") {
  47. state.selectGarminDevices()
  48. }
  49. }
  50. }
  51. .scrollContentBackground(.hidden).background(color)
  52. .onAppear(perform: configureView)
  53. .navigationTitle("Watch Configuration")
  54. .navigationBarTitleDisplayMode(.automatic)
  55. }
  56. private func onDelete(offsets: IndexSet) {
  57. state.devices.remove(atOffsets: offsets)
  58. state.deleteGarminDevice()
  59. }
  60. }
  61. }