AppleHealthKitRootView.swift 3.7 KB

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