another.im-ios/ConversationsClassic/View/SharedComponents/SharedNavigationBar.swift
2024-08-07 10:36:33 +02:00

79 lines
1.8 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
var body: some View {
Text(text)
.font(.head2)
.foregroundColor(.Material.Text.main)
}
}
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)
}
}