OpenMockPumpSettingsOnLongPressGesture.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // OpenMockPumpSettingsOnLongPressGesture.swift
  3. // MockKitUI
  4. //
  5. // Created by Nathaniel Hamming on 2023-05-18.
  6. // Copyright © 2023 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import LoopKit
  10. import MockKit
  11. extension View {
  12. func openMockPumpSettingsOnLongPress(enabled: Bool = true, minimumDuration: Double = 5, pumpManager: MockPumpManager, supportedInsulinTypes: [InsulinType]) -> some View {
  13. modifier(OpenMockPumpSettingsOnLongPressGesture(enabled: enabled, minimumDuration: minimumDuration, pumpManager: pumpManager, supportedInsulinTypes: supportedInsulinTypes))
  14. }
  15. }
  16. fileprivate struct OpenMockPumpSettingsOnLongPressGesture: ViewModifier {
  17. private let enabled: Bool
  18. private let minimumDuration: TimeInterval
  19. private let pumpManager: MockPumpManager
  20. private let supportedInsulinTypes: [InsulinType]
  21. @State private var mockPumpSettingsDisplayed = false
  22. init(enabled: Bool, minimumDuration: Double, pumpManager: MockPumpManager, supportedInsulinTypes: [InsulinType]) {
  23. self.enabled = enabled
  24. self.minimumDuration = minimumDuration
  25. self.pumpManager = pumpManager
  26. self.supportedInsulinTypes = supportedInsulinTypes
  27. }
  28. func body(content: Content) -> some View {
  29. modifiedContent(content: content)
  30. }
  31. func modifiedContent(content: Content) -> some View {
  32. ZStack {
  33. content
  34. .onLongPressGesture(minimumDuration: minimumDuration) {
  35. mockPumpSettingsDisplayed = true
  36. }
  37. NavigationLink(destination: MockPumpManagerControlsView(pumpManager: pumpManager, supportedInsulinTypes: supportedInsulinTypes), isActive: $mockPumpSettingsDisplayed) {
  38. EmptyView()
  39. }
  40. .opacity(0) // <- Hides the Chevron
  41. .buttonStyle(PlainButtonStyle())
  42. .disabled(true)
  43. }
  44. }
  45. }