Last active
June 9, 2020 13:08
-
-
Save archieedwards/d2a8122e3f87204ac3996d86e7ecf40e to your computer and use it in GitHub Desktop.
base structure for the Your Library view..
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 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