| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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: "Allow Trio to read from and write to Apple Health \nDefault: OFF",
- verboseHint: VStack {
- Text("Default: OFF").bold()
- VStack(alignment: .leading, spacing: 10) {
- Text("This allows Trio to read from and write to Apple Health.")
- Text("Warning: 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)
- VStack(alignment: .leading, spacing: 5) {
- Text("1. Open the Settings app on your iOS device")
- Text("2. Scroll down or type \"Health\" in the settings search bar and select the \"Health\" app")
- Text("3. Tap on \"Data Access & Devices\"")
- Text("4. Find and select \"Trio\" from the list of apps")
- Text("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)
- }
- }
- }
|