forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuideNavigationButton.swift
More file actions
45 lines (41 loc) · 1.41 KB
/
GuideNavigationButton.swift
File metadata and controls
45 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// GuideNavigationButton.swift
// LoopKitUI
//
// Created by Pete Schwamb on 2020-03-04.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
public struct GuideNavigationButton<Destination>: View where Destination: View {
@Binding var navigationLinkIsActive: Bool
private let label: String
private let buttonPressedAction: (() -> Void)?
private let buttonStyle: ActionButton.ButtonType
private let destination: () -> Destination
public init(navigationLinkIsActive: Binding<Bool>,
label: String,
buttonPressedAction: (() -> Void)? = nil,
buttonStyle: ActionButton.ButtonType = .primary,
@ViewBuilder destination: @escaping () -> Destination)
{
self._navigationLinkIsActive = navigationLinkIsActive
self.label = label
self.buttonPressedAction = buttonPressedAction
self.buttonStyle = buttonStyle
self.destination = destination
}
public var body: some View {
NavigationLink(destination: destination(),
isActive: self.$navigationLinkIsActive)
{
Button(action: {
self.buttonPressedAction?()
self.navigationLinkIsActive = true
}) {
Text(label)
.actionButtonStyle(buttonStyle)
}
}
.isDetailLink(false)
}
}