AppleHealthKitRootView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: AnyView?
  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.map { AnyView($0) }
  40. hintLabel = "Connect to Apple Health"
  41. }
  42. ),
  43. units: state.units,
  44. type: .boolean,
  45. label: "Connect to Apple Health",
  46. miniHint: "Allows Trio to read from and write to Apple Health.",
  47. verboseHint: Text(
  48. NSLocalizedString(
  49. "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.",
  50. comment: "Suspend Zeros IOB"
  51. )
  52. ),
  53. headerText: "Apple Health Integration"
  54. )
  55. if !state.needShowInformationTextForSetPermissions {
  56. Section {
  57. VStack {
  58. HStack {
  59. Image(systemName: "exclamationmark.circle.fill")
  60. Text("Give Apple Health Write Permissions")
  61. }.padding(.bottom)
  62. Text("""
  63. 1. Open the Settings app on your iOS device.
  64. 2. Scroll down and select "Health."
  65. 3. Tap on "Data Access & Devices."
  66. 4. Find and select "Trio" from the list of apps.
  67. 5. Ensure that the "Write Data" option is enabled for the desired health metrics.
  68. """).font(.footnote)
  69. }
  70. .padding(.vertical)
  71. .foregroundColor(Color.secondary)
  72. }.listRowBackground(Color.chart)
  73. }
  74. }
  75. .sheet(isPresented: $shouldDisplayHint) {
  76. SettingInputHintView(
  77. hintDetent: $hintDetent,
  78. shouldDisplayHint: $shouldDisplayHint,
  79. hintLabel: hintLabel ?? "",
  80. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  81. sheetTitle: "Help"
  82. )
  83. }
  84. .scrollContentBackground(.hidden).background(color)
  85. .onAppear(perform: configureView)
  86. .navigationTitle("Apple Health")
  87. .navigationBarTitleDisplayMode(.automatic)
  88. }
  89. }
  90. }