91 lines
2.1 KiB
Swift
91 lines
2.1 KiB
Swift
|
import SwiftUI
|
||
|
|
||
|
struct SharedNavBarButton: View {
|
||
|
let image: Image?
|
||
|
let action: () -> Void
|
||
|
var isEnabled: Bool = true
|
||
|
|
||
|
init(
|
||
|
image: Image,
|
||
|
action: @escaping () -> Void,
|
||
|
isEnabled: Bool = true
|
||
|
) {
|
||
|
self.image = image
|
||
|
self.action = action
|
||
|
self.isEnabled = isEnabled
|
||
|
}
|
||
|
|
||
|
var body: some View {
|
||
|
Button {
|
||
|
action()
|
||
|
} label: {
|
||
|
image
|
||
|
.foregroundColor(isEnabled ? .Material.Elements.active : .Material.Elements.inactive)
|
||
|
.tappablePadding(.symmetric(12)) {
|
||
|
action()
|
||
|
}
|
||
|
}
|
||
|
.disabled(!isEnabled)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct SharedNavBarText: View {
|
||
|
let text: String
|
||
|
let action: (() -> Void)?
|
||
|
|
||
|
init(
|
||
|
text: String,
|
||
|
action: (() -> Void)? = nil
|
||
|
) {
|
||
|
self.text = text
|
||
|
self.action = action
|
||
|
}
|
||
|
|
||
|
var body: some View {
|
||
|
Text(text)
|
||
|
.font(.head2)
|
||
|
.foregroundColor(.Material.Text.main)
|
||
|
.tappablePadding(.init(top: 8, leading: 24, bottom: 8, trailing: 24)) {
|
||
|
action?()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct SharedNavigationBar: View {
|
||
|
var leftButton: SharedNavBarButton?
|
||
|
var centerText: SharedNavBarText?
|
||
|
var rightButton: SharedNavBarButton?
|
||
|
|
||
|
var body: some View {
|
||
|
ZStack {
|
||
|
Color.Material.Background.dark
|
||
|
.ignoresSafeArea()
|
||
|
|
||
|
VStack {
|
||
|
if centerText != nil {
|
||
|
centerText
|
||
|
}
|
||
|
}
|
||
|
Spacer()
|
||
|
|
||
|
HStack(alignment: .center) {
|
||
|
VStack {
|
||
|
if leftButton != nil {
|
||
|
leftButton?.padding()
|
||
|
}
|
||
|
}
|
||
|
.frame(minWidth: 40)
|
||
|
Spacer()
|
||
|
VStack {
|
||
|
if rightButton != nil {
|
||
|
rightButton?
|
||
|
.padding()
|
||
|
}
|
||
|
}
|
||
|
.frame(minWidth: 40)
|
||
|
}
|
||
|
}
|
||
|
.frame(height: 44)
|
||
|
}
|
||
|
}
|