Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save archieedwards/15991989008142ef3f0b204ccd7ffac9 to your computer and use it in GitHub Desktop.
Save archieedwards/15991989008142ef3f0b204ccd7ffac9 to your computer and use it in GitHub Desktop.
View to show sub categories and green indicator bar
struct SubCategoryText: View {
var subCategorys : [String]
@Binding var currentSubCategoryIndex : Int
@Binding var indicatorOffset : CGFloat
var body: some View {
HStack{
subCategory(index: 0, parent: self)
subCategory(index: 1, parent: self)
subCategory(index: 2, parent: self)
Spacer()
}
}
struct subCategory: View{
var index: Int
var parent: SubCategoryText
var body: some View{
VStack{
Text(parent.subCategorys[index])
.font(.headline)
.foregroundColor(parent.currentSubCategoryIndex == index ? .primary : .secondary)
.onTapGesture {
withAnimation(.easeIn,{
self.parent.currentSubCategoryIndex = self.index
})
}
Rectangle()
.frame(height: 2)
.offset(x: parent.indicatorOffset)
.foregroundColor(parent.currentSubCategoryIndex == index ? .green : .clear)
.animation(.none)
}.fixedSize().padding(.leading)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment