Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save archieedwards/d2a8122e3f87204ac3996d86e7ecf40e to your computer and use it in GitHub Desktop.
Save archieedwards/d2a8122e3f87204ac3996d86e7ecf40e to your computer and use it in GitHub Desktop.
base structure for the Your Library view..
struct YourLibraryView: View {
@State var page: Int = 0 //// keeps track of which category index we are at
@State var nestedPages: [Int] = [0, 0] /// keeps track of which sub category index we are at for each category
@State var indicatorOffsets : [CGFloat] = [0,0] /// keepts track of indicator offsets for each category
var data = Array(0..<2)
var nestedData = Array(0..<3)
var body: some View {
VStack{
CategoryText(currentCategoryIndex: self.$page, nestedPages: self.$nestedPages)
Pager(page: self.$page,
data: self.data,
id: \.self) { page in
self.nestedPager(page)
}
.swipeInteractionArea(.allAvailable)
}
}
/// nestedPager contains subcategory titles, an indicator and a pager to show subcategory views
func nestedPager(_ index: Int) -> some View {
let currentSubCategory = Binding<Int>(
get: {
self.nestedPages[index]
}, set: { newValue in
var newNestedPages = self.nestedPages
newNestedPages[index] = newValue
self.nestedPages = newNestedPages
})
let indicatorOffset = Binding<CGFloat>(
get: {
self.indicatorOffsets[index]
}, set: { newValue in
var newIndicatorOffsets = self.indicatorOffsets
newIndicatorOffsets[index] = newValue
self.indicatorOffsets = newIndicatorOffsets
})
return VStack(alignment: .leading, spacing: 20){
SubCategoryText(subCategorys: index == 0 ? ["Playlists", "Albums", "Artists"] : ["Episodes", "Downloads", "Shows"], currentSubCategoryIndex: currentSubCategory, indicatorOffset: indicatorOffset)
Pager(page: currentSubCategory,
data: self.nestedData,
id: \.self) { page in
MediaContentView()
}
Spacer()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment