AppleHealthKitRootView.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. @Environment(AppState.self) var appState
  15. var body: some View {
  16. Form {
  17. SettingInputSection(
  18. decimalValue: $decimalPlaceholder,
  19. booleanValue: $state.useAppleHealth,
  20. shouldDisplayHint: $shouldDisplayHint,
  21. selectedVerboseHint: Binding(
  22. get: { selectedVerboseHint },
  23. set: {
  24. selectedVerboseHint = $0
  25. hintLabel = "Connect to Apple Health"
  26. }
  27. ),
  28. units: state.units,
  29. type: .boolean,
  30. label: "Connect to Apple Health",
  31. miniHint: "Allows Trio to read from and write to Apple Health.",
  32. verboseHint: NSLocalizedString(
  33. "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.",
  34. comment: "Suspend Zeros IOB"
  35. ),
  36. headerText: "Apple Health Integration"
  37. )
  38. if !state.needShowInformationTextForSetPermissions {
  39. Section {
  40. VStack {
  41. HStack {
  42. Image(systemName: "exclamationmark.circle.fill")
  43. Text("Give Apple Health Write Permissions")
  44. }.padding(.bottom)
  45. Text("""
  46. 1. Open the Settings app on your iOS device.
  47. 2. Scroll down and select "Health."
  48. 3. Tap on "Data Access & Devices."
  49. 4. Find and select "Trio" from the list of apps.
  50. 5. Ensure that the "Write Data" option is enabled for the desired health metrics.
  51. """).font(.footnote)
  52. }
  53. .padding(.vertical)
  54. .foregroundColor(Color.secondary)
  55. }.listRowBackground(Color.chart)
  56. }
  57. }
  58. .sheet(isPresented: $shouldDisplayHint) {
  59. SettingInputHintView(
  60. hintDetent: $hintDetent,
  61. shouldDisplayHint: $shouldDisplayHint,
  62. hintLabel: hintLabel ?? "",
  63. hintText: selectedVerboseHint ?? "",
  64. sheetTitle: "Help"
  65. )
  66. }
  67. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  68. .onAppear(perform: configureView)
  69. .navigationTitle("Apple Health")
  70. .navigationBarTitleDisplayMode(.automatic)
  71. }
  72. }
  73. }