AppleHealthKitRootView.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.bgDarkBlue,
  12. Color.bgDarkerDarkBlue
  13. ]),
  14. startPoint: .top,
  15. endPoint: .bottom
  16. )
  17. :
  18. LinearGradient(
  19. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. }
  24. var body: some View {
  25. Form {
  26. Section {
  27. Toggle("Connect to Apple Health", isOn: $state.useAppleHealth)
  28. HStack {
  29. Image(systemName: "pencil.circle.fill")
  30. Text(
  31. "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."
  32. )
  33. .font(.caption)
  34. }
  35. .foregroundColor(Color.secondary)
  36. if state.needShowInformationTextForSetPermissions {
  37. HStack {
  38. Image(systemName: "exclamationmark.circle.fill")
  39. Text("For write data to Apple Health you must give permissions in Settings > Health > Data Access")
  40. .font(.caption)
  41. }
  42. .foregroundColor(Color.secondary)
  43. }
  44. }
  45. }
  46. .scrollContentBackground(.hidden).background(color)
  47. .onAppear(perform: configureView)
  48. .navigationTitle("Apple Health")
  49. .navigationBarTitleDisplayMode(.automatic)
  50. }
  51. }
  52. }