ShortcutsConfigView.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: AnyView?
  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. private var color: LinearGradient {
  17. colorScheme == .dark ? LinearGradient(
  18. gradient: Gradient(colors: [
  19. Color.bgDarkBlue,
  20. Color.bgDarkerDarkBlue
  21. ]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. :
  26. LinearGradient(
  27. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  28. startPoint: .top,
  29. endPoint: .bottom
  30. )
  31. }
  32. var body: some View {
  33. Form {
  34. Section(
  35. header: Text("Shortcuts Integration"),
  36. content: {
  37. Text(
  38. "Trio lets you create automations using iOS Shortcuts. Go to the Shortcuts app to create new automations."
  39. )
  40. }
  41. ).listRowBackground(Color.chart)
  42. Section {
  43. Button {
  44. UIApplication.shared.open(URL(string: "shortcuts://")!)
  45. }
  46. label: { Label("Open iOS Shortcuts", systemImage: "arrow.triangle.branch").font(.title3).padding() }
  47. .frame(maxWidth: .infinity, alignment: .center)
  48. .buttonStyle(.bordered)
  49. }
  50. .listRowBackground(Color.clear)
  51. SettingInputSection(
  52. decimalValue: $decimalPlaceholder,
  53. booleanValue: $state.allowBolusByShortcuts,
  54. shouldDisplayHint: $shouldDisplayHint,
  55. selectedVerboseHint: Binding(
  56. get: { selectedVerboseHint },
  57. set: {
  58. selectedVerboseHint = $0.map { AnyView($0) }
  59. hintLabel = "Allow Bolusing with Shortcuts"
  60. }
  61. ),
  62. units: state.units,
  63. type: .boolean,
  64. label: "Allow Bolusing with Shortcuts",
  65. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  66. verboseHint: Text("Allow Bolusing with Shortcuts… bla bla bla")
  67. )
  68. }
  69. .sheet(isPresented: $shouldDisplayHint) {
  70. SettingInputHintView(
  71. hintDetent: $hintDetent,
  72. shouldDisplayHint: $shouldDisplayHint,
  73. hintLabel: hintLabel ?? "",
  74. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  75. sheetTitle: "Help"
  76. )
  77. }
  78. .scrollContentBackground(.hidden).background(color)
  79. .onAppear(perform: configureView)
  80. .navigationTitle("Shortcuts")
  81. .navigationBarTitleDisplayMode(.automatic)
  82. }
  83. }
  84. }