WatchConfigAppleWatchView.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import SwiftUI
  2. import Swinject
  3. struct WatchConfigAppleWatchView: BaseView {
  4. let resolver: Resolver
  5. @ObservedObject var state: WatchConfig.StateModel
  6. @State private var shouldDisplayHint: Bool = false
  7. @State var hintDetent = PresentationDetent.large
  8. @State var selectedVerboseHint: AnyView?
  9. @State var hintLabel: String?
  10. @State private var decimalPlaceholder: Decimal = 0.0
  11. @State private var booleanPlaceholder: Bool = false
  12. @Environment(\.colorScheme) var colorScheme
  13. @Environment(AppState.self) var appState
  14. private func onDelete(offsets: IndexSet) {
  15. state.devices.remove(atOffsets: offsets)
  16. state.deleteGarminDevice()
  17. }
  18. var body: some View {
  19. List {
  20. SettingInputSection(
  21. decimalValue: $decimalPlaceholder,
  22. booleanValue: $state.confirmBolusFaster,
  23. shouldDisplayHint: $shouldDisplayHint,
  24. selectedVerboseHint: Binding(
  25. get: { selectedVerboseHint },
  26. set: {
  27. selectedVerboseHint = $0.map { AnyView($0) }
  28. hintLabel = "Confirm Bolus Faster"
  29. }
  30. ),
  31. units: state.units,
  32. type: .boolean,
  33. label: "Confirm Bolus Faster",
  34. miniHint: "Reduce the number of crown rotations required for bolus confirmation.",
  35. verboseHint: Text(
  36. "Enabling this feature lowers the number of turns on the crown dial required when confirming a bolus."
  37. ),
  38. headerText: "Apple Watch Configuration"
  39. )
  40. Section(
  41. header: Text("Contact Image"),
  42. content: {
  43. VStack {
  44. HStack {
  45. NavigationLink("Contacts Configuration") {
  46. ContactImage.RootView(resolver: resolver)
  47. }.foregroundStyle(Color.accentColor)
  48. }
  49. }
  50. }
  51. ).listRowBackground(Color.chart)
  52. }
  53. .listSectionSpacing(sectionSpacing)
  54. .sheet(isPresented: $shouldDisplayHint) {
  55. SettingInputHintView(
  56. hintDetent: $hintDetent,
  57. shouldDisplayHint: $shouldDisplayHint,
  58. hintLabel: hintLabel ?? "",
  59. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  60. sheetTitle: "Help"
  61. )
  62. }
  63. .navigationTitle("Apple Watch")
  64. .navigationBarTitleDisplayMode(.automatic)
  65. .scrollContentBackground(.hidden)
  66. .background(appState.trioBackgroundColor(for: colorScheme))
  67. }
  68. }