Last active
June 9, 2020 10:58
-
-
Save archieedwards/15991989008142ef3f0b204ccd7ffac9 to your computer and use it in GitHub Desktop.
View to show sub categories and green indicator bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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