AppleHealthKitRootView.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import SwiftUI
  2. import Swinject
  3. extension AppleHealthKit {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color("Background_1"),
  12. Color("Background_1"),
  13. Color("Background_2")
  14. // Color("Background_1")
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. var body: some View {
  27. Form {
  28. Section {
  29. Toggle("Connect to Apple Health", isOn: $state.useAppleHealth)
  30. HStack {
  31. Image(systemName: "pencil.circle.fill")
  32. Text(
  33. "This allows iAPS to read from and write to Apple Heath. You must also give permissions in Settings > Health > Data Access. If you enter a glucose value into Apple Health, open iAPS to confirm it shows up."
  34. )
  35. .font(.caption)
  36. }
  37. .foregroundColor(Color.secondary)
  38. if state.needShowInformationTextForSetPermissions {
  39. HStack {
  40. Image(systemName: "exclamationmark.circle.fill")
  41. Text("For write data to Apple Health you must give permissions in Settings > Health > Data Access")
  42. .font(.caption)
  43. }
  44. .foregroundColor(Color.secondary)
  45. }
  46. }
  47. }
  48. .scrollContentBackground(.hidden).background(color)
  49. .onAppear(perform: configureView)
  50. .navigationTitle("Apple Health")
  51. .navigationBarTitleDisplayMode(.automatic)
  52. }
  53. }
  54. }