2024-01-02 14:23:36 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-03-09 15:57:02 +01:00
|
|
|
//TODO: Changes this for ONLY timeline picker
|
|
|
|
|
2024-01-02 14:23:36 +01:00
|
|
|
struct MetaPicker<Content : View>: View {
|
|
|
|
@Namespace private var metaPicker
|
|
|
|
@Namespace private var selectBar
|
|
|
|
|
|
|
|
var items: [String]
|
|
|
|
@Binding var selectedItem: String
|
|
|
|
|
|
|
|
@ViewBuilder let content: (_ item: String) -> Content
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
ForEach(items, id: \.self) { item in
|
|
|
|
GeometryReader { geo in
|
|
|
|
let size = geo.size
|
|
|
|
VStack {
|
|
|
|
content(item)
|
|
|
|
.tag(item)
|
|
|
|
.foregroundStyle(item == selectedItem ? Color.white : Color.gray.opacity(0.3))
|
|
|
|
|
|
|
|
if item == selectedItem {
|
|
|
|
Rectangle()
|
|
|
|
.fill(Color.white)
|
|
|
|
.frame(width: size.width, height: 2)
|
|
|
|
.matchedGeometryEffect(id: selectBar, in: metaPicker)
|
|
|
|
} else {
|
|
|
|
Rectangle()
|
|
|
|
.fill(Color.gray.opacity(0.3))
|
|
|
|
.frame(width: size.width, height: 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
.onTapGesture {
|
|
|
|
withAnimation(.spring) {
|
|
|
|
selectedItem = item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if items.last != item {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.vertical)
|
|
|
|
}
|
|
|
|
}
|