| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import SwiftUI
- import Swinject
- extension AppleHealthKit {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: AnyView?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var booleanPlaceholder: Bool = false
- @Environment(\.colorScheme) var colorScheme
- var color: LinearGradient {
- colorScheme == .dark ? LinearGradient(
- gradient: Gradient(colors: [
- Color.bgDarkBlue,
- Color.bgDarkerDarkBlue
- ]),
- startPoint: .top,
- endPoint: .bottom
- )
- :
- LinearGradient(
- gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
- startPoint: .top,
- endPoint: .bottom
- )
- }
- var body: some View {
- Form {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.useAppleHealth,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0.map { AnyView($0) }
- hintLabel = "Connect to Apple Health"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Connect to Apple Health",
- miniHint: """
- Allows Trio to read from and write to Apple Health
- Default: OFF
- """,
- verboseHint: VStack {
- Text("Default: OFF").bold()
- Text("""
- This allows Trio to read from and write to Apple Health.
- """)
- Text("You must also give permissions in iOS System Settings for the Health app.").bold().italic()
- },
- headerText: "Apple Health Integration"
- )
- if !state.needShowInformationTextForSetPermissions {
- Section {
- VStack {
- HStack {
- Image(systemName: "exclamationmark.circle.fill")
- Text("Give Apple Health Write Permissions")
- }.padding(.bottom)
- Text("""
- 1. Open the Settings app on your iOS device
- 2. Scroll down or type "Health" in the settings search bar and select the "Health" app
- 3. Tap on "Data Access & Devices"
- 4. Find and select "Trio" from the list of apps
- 5. Ensure that the "Write Data" option is enabled for the desired health metrics
- """).font(.footnote)
- }
- .padding(.vertical)
- .foregroundColor(Color.secondary)
- }.listRowBackground(Color.chart)
- }
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? AnyView(EmptyView()),
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(color)
- .onAppear(perform: configureView)
- .navigationTitle("Apple Health")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|