AppleHealthKitRootView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import SwiftUI
  2. import Swinject
  3. extension AppleHealthKit {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: String?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. var color: LinearGradient {
  15. colorScheme == .dark ? LinearGradient(
  16. gradient: Gradient(colors: [
  17. Color.bgDarkBlue,
  18. Color.bgDarkerDarkBlue
  19. ]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. :
  24. LinearGradient(
  25. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  26. startPoint: .top,
  27. endPoint: .bottom
  28. )
  29. }
  30. var body: some View {
  31. Form {
  32. SettingInputSection(
  33. decimalValue: $decimalPlaceholder,
  34. booleanValue: $state.useAppleHealth,
  35. shouldDisplayHint: $shouldDisplayHint,
  36. selectedVerboseHint: Binding(
  37. get: { selectedVerboseHint },
  38. set: {
  39. selectedVerboseHint = $0
  40. hintLabel = "Connect to Apple Health"
  41. }
  42. ),
  43. type: .boolean,
  44. label: "Connect to Apple Health",
  45. miniHint: "Allows Trio to read from and write to Apple Health.",
  46. verboseHint: NSLocalizedString(
  47. "This allows Trio to read from and write to Apple Health. You must also give permissions in iOS Settings > Health > Data Access. If you enter a glucose value into Apple Health, open Trio to confirm it shows up.",
  48. comment: "Suspend Zeros IOB"
  49. ),
  50. headerText: "Apple Health Integration"
  51. )
  52. if !state.needShowInformationTextForSetPermissions {
  53. Section {
  54. VStack {
  55. HStack {
  56. Image(systemName: "exclamationmark.circle.fill")
  57. Text("Give Apple Health Write Permissions")
  58. }.padding(.bottom)
  59. Text("""
  60. 1. Open the Settings app on your iOS device.
  61. 2. Scroll down and select "Health."
  62. 3. Tap on "Data Access & Devices."
  63. 4. Find and select "Trio" from the list of apps.
  64. 5. Ensure that the "Write Data" option is enabled for the desired health metrics.
  65. """).font(.footnote)
  66. }
  67. .padding(.vertical)
  68. .foregroundColor(Color.secondary)
  69. }.listRowBackground(Color.chart)
  70. }
  71. }
  72. .sheet(isPresented: $shouldDisplayHint) {
  73. SettingInputHintView(
  74. hintDetent: $hintDetent,
  75. shouldDisplayHint: $shouldDisplayHint,
  76. hintLabel: hintLabel ?? "",
  77. hintText: selectedVerboseHint ?? "",
  78. sheetTitle: "Help"
  79. )
  80. }
  81. .scrollContentBackground(.hidden).background(color)
  82. .onAppear(perform: configureView)
  83. .navigationTitle("Apple Health")
  84. .navigationBarTitleDisplayMode(.automatic)
  85. }
  86. }
  87. }