ShortcutsConfigView.swift 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 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
  59. hintLabel = "Allow Bolusing with Shortcuts"
  60. }
  61. ),
  62. type: .boolean,
  63. label: "Allow Bolusing with Shortcuts",
  64. miniHint: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr.",
  65. verboseHint: "Allow Bolusing with Shortcuts… bla bla bla"
  66. )
  67. }
  68. .sheet(isPresented: $shouldDisplayHint) {
  69. SettingInputHintView(
  70. hintDetent: $hintDetent,
  71. shouldDisplayHint: $shouldDisplayHint,
  72. hintLabel: hintLabel ?? "",
  73. hintText: selectedVerboseHint ?? "",
  74. sheetTitle: "Help"
  75. )
  76. }
  77. .scrollContentBackground(.hidden).background(color)
  78. .onAppear(perform: configureView)
  79. .navigationTitle("Shortcuts")
  80. .navigationBarTitleDisplayMode(.automatic)
  81. }
  82. }
  83. }