Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Last active August 15, 2020 13:20
Show Gist options
  • Save prafullakumar/0aa843a376365637b2f8d221fbf1e6df to your computer and use it in GitHub Desktop.
Save prafullakumar/0aa843a376365637b2f8d221fbf1e6df to your computer and use it in GitHub Desktop.
struct TabBar: View {
@ObservedObject var tabItems: TabItems
let padding: CGFloat = 5
let iconeSize: CGFloat = 20
var iconFrame: CGFloat {
(padding * 2) + iconeSize
}
var tabItemCount: CGFloat {
CGFloat(tabItems.items.count)
}
var spacing: CGFloat { //padding b/w cells
(UIScreen.main.bounds.width - (iconFrame * tabItemCount)) / (tabItemCount + 1)
}
var firstCenter: CGFloat { //pos of first view
spacing + iconFrame/2
}
var stepperToNextCenter: CGFloat { //distance between tab Items
spacing + iconFrame //half of 1 and half of next
}
var body: some View {
VStack {
Spacer()
ZStack {
///Add bar logic here
HStack(spacing: spacing) {
ForEach(0..<tabItems.items.count, id: \.self) { i in
ZStack {
Image(systemName: self.tabItems.items[i].imageName)
.resizable()
.foregroundColor(Color.gray)
.frame(width: self.iconeSize, height: self.iconeSize)
.opacity(self.tabItems.items[i].opacity)
.padding(.all, padding)
.background(Color.white)
.clipShape(Circle())
.onTapGesture {
withAnimation(Animation.easeInOut) {
self.tabItems.select(i)
}
}
}
.offset(y: self.tabItems.items[i].offset)
}
}
.edgesIgnoringSafeArea(.all)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment