WatchConfigGarminView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import SwiftUI
  2. struct WatchConfigGarminView: View {
  3. @ObservedObject var state: WatchConfig.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State var selectedVerboseHint: AnyView?
  7. @State var hintLabel: String?
  8. @State private var decimalPlaceholder: Decimal = 0.0
  9. @State private var booleanPlaceholder: Bool = false
  10. @Environment(\.colorScheme) var colorScheme
  11. var color: LinearGradient {
  12. colorScheme == .dark ? LinearGradient(
  13. gradient: Gradient(colors: [
  14. Color.bgDarkBlue,
  15. Color.bgDarkerDarkBlue
  16. ]),
  17. startPoint: .top,
  18. endPoint: .bottom
  19. )
  20. :
  21. LinearGradient(
  22. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  23. startPoint: .top,
  24. endPoint: .bottom
  25. )
  26. }
  27. private func onDelete(offsets: IndexSet) {
  28. state.devices.remove(atOffsets: offsets)
  29. state.deleteGarminDevice()
  30. }
  31. var body: some View {
  32. Form {
  33. Section(
  34. header: Text("Garmin Configuration"),
  35. content:
  36. {
  37. VStack {
  38. Button {
  39. state.selectGarminDevices()
  40. } label: {
  41. Text("Add Device")
  42. .font(.title3) }
  43. .frame(maxWidth: .infinity, alignment: .center)
  44. .buttonStyle(.bordered)
  45. HStack(alignment: .top) {
  46. Text(
  47. "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Add Device"
  56. selectedVerboseHint = AnyView(Text("Add Garmin Device… bla bla bla"))
  57. shouldDisplayHint.toggle()
  58. },
  59. label: {
  60. HStack {
  61. Image(systemName: "questionmark.circle")
  62. }
  63. }
  64. ).buttonStyle(BorderlessButtonStyle())
  65. }.padding(.top)
  66. }.padding(.vertical)
  67. }
  68. ).listRowBackground(Color.chart)
  69. if !state.devices.isEmpty {
  70. Section(header: Text("Garmin Watch")) {
  71. List {
  72. ForEach(state.devices, id: \.uuid) { device in
  73. Text(device.friendlyName)
  74. }
  75. .onDelete(perform: onDelete)
  76. }
  77. }.listRowBackground(Color.chart)
  78. }
  79. }
  80. .sheet(isPresented: $shouldDisplayHint) {
  81. SettingInputHintView(
  82. hintDetent: $hintDetent,
  83. shouldDisplayHint: $shouldDisplayHint,
  84. hintLabel: hintLabel ?? "",
  85. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  86. sheetTitle: "Help"
  87. )
  88. }
  89. .navigationTitle("Garmin")
  90. .navigationBarTitleDisplayMode(.automatic)
  91. .scrollContentBackground(.hidden).background(color)
  92. }
  93. }