ShortcutsConfigView.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Combine
  2. import SwiftUI
  3. import Swinject
  4. import UIKit
  5. extension ShortcutsConfig {
  6. struct RootView: BaseView {
  7. let resolver: Resolver
  8. @StateObject var state = StateModel()
  9. @State private var shouldDisplayHint: Bool = false
  10. @State var hintDetent = PresentationDetent.large
  11. @State var selectedVerboseHint: String?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var booleanPlaceholder: Bool = false
  15. @Environment(\.colorScheme) var colorScheme
  16. @Environment(AppState.self) var appState
  17. var body: some View {
  18. Form {
  19. Section(
  20. header: Text("Shortcuts Integration"),
  21. content: {
  22. Text(
  23. "Trio lets you create automations using iOS Shortcuts. Go to the Shortcuts app to create new automations."
  24. )
  25. }
  26. ).listRowBackground(Color.chart)
  27. Section {
  28. Button {
  29. UIApplication.shared.open(URL(string: "shortcuts://")!)
  30. }
  31. label: { Label("Open iOS Shortcuts", systemImage: "arrow.triangle.branch").font(.title3).padding() }
  32. .frame(maxWidth: .infinity, alignment: .center)
  33. .buttonStyle(.bordered)
  34. }
  35. .listRowBackground(Color.clear)
  36. SettingInputSection(
  37. decimalValue: $decimalPlaceholder,
  38. booleanValue: $state.allowBolusByShortcuts,
  39. shouldDisplayHint: $shouldDisplayHint,
  40. selectedVerboseHint: Binding(
  41. get: { selectedVerboseHint },
  42. set: {
  43. selectedVerboseHint = $0
  44. hintLabel = "Allow Bolusing with Shortcuts"
  45. }
  46. ),
  47. units: state.units,
  48. type: .boolean,
  49. label: "Allow Bolusing with Shortcuts",
  50. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  51. verboseHint: "Allow Bolusing with Shortcuts… bla bla bla"
  52. )
  53. }
  54. .sheet(isPresented: $shouldDisplayHint) {
  55. SettingInputHintView(
  56. hintDetent: $hintDetent,
  57. shouldDisplayHint: $shouldDisplayHint,
  58. hintLabel: hintLabel ?? "",
  59. hintText: selectedVerboseHint ?? "",
  60. sheetTitle: "Help"
  61. )
  62. }
  63. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  64. .onAppear(perform: configureView)
  65. .navigationTitle("Shortcuts")
  66. .navigationBarTitleDisplayMode(.automatic)
  67. }
  68. }
  69. }