AppleHealthKitRootView.swift 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: VStack {
  48. Text("""
  49. This allows Trio to read from and write to Apple Health.
  50. You must also give permissions in iOS Settings > Health > Data Access.
  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. }