GuideNavigationButton.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // GuideNavigationButton.swift
  3. // LoopKitUI
  4. //
  5. // Created by Pete Schwamb on 2020-03-04.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct GuideNavigationButton<Destination>: View where Destination: View {
  10. @Binding var navigationLinkIsActive: Bool
  11. private let label: String
  12. private let buttonPressedAction: (() -> Void)?
  13. private let buttonStyle: ActionButton.ButtonType
  14. private let destination: () -> Destination
  15. public init(navigationLinkIsActive: Binding<Bool>,
  16. label: String,
  17. buttonPressedAction: (() -> Void)? = nil,
  18. buttonStyle: ActionButton.ButtonType = .primary,
  19. @ViewBuilder destination: @escaping () -> Destination)
  20. {
  21. self._navigationLinkIsActive = navigationLinkIsActive
  22. self.label = label
  23. self.buttonPressedAction = buttonPressedAction
  24. self.buttonStyle = buttonStyle
  25. self.destination = destination
  26. }
  27. public var body: some View {
  28. NavigationLink(destination: destination(),
  29. isActive: self.$navigationLinkIsActive)
  30. {
  31. Button(action: {
  32. self.buttonPressedAction?()
  33. self.navigationLinkIsActive = true
  34. }) {
  35. Text(label)
  36. .actionButtonStyle(buttonStyle)
  37. }
  38. }
  39. .isDetailLink(false)
  40. }
  41. }