AppleHealthKitRootView.swift 4.1 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: "Allow Trio to read from and write to Apple Health.",
  47. verboseHint:
  48. VStack(alignment: .leading, spacing: 10) {
  49. Text("Default: OFF").bold()
  50. Text("This allows Trio to read from and write to Apple Health.")
  51. Text("Warning: You must also give permissions in iOS System Settings for the Health app.").bold()
  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. VStack(alignment: .leading, spacing: 5) {
  63. Text("1. Open the Settings app on your iOS device")
  64. Text("2. Scroll down or type \"Health\" in the settings search bar and select the \"Health\" app")
  65. Text("3. Tap on \"Data Access & Devices\"")
  66. Text("4. Find and select \"Trio\" from the list of apps")
  67. Text("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. }