If looking at totals roll up should be totals, if percentage then percentages should show
This commit is contained in:
Trey t
2022-02-10 16:15:06 -06:00
parent f66caf93dd
commit 97e6e52c8c
4 changed files with 114 additions and 59 deletions

View File

@@ -7,30 +7,50 @@
import SwiftUI
enum MainSwitchableViewType: Int, CaseIterable {
case total
case percentageCircle
case percentage
func next() -> MainSwitchableViewType {
let currentValue = self.rawValue
var next = currentValue + 1
if next == MainSwitchableViewType.allCases.count {
next = 0
}
return MainSwitchableViewType(rawValue: next) ?? .total
}
}
struct SwitchableView: View {
@State var currentViewIdx = 0
@State var viewType: MainSwitchableViewType = .total
var headerTypeChanged: ((MainSwitchableViewType) -> Void)
let daysBack: Int
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
let daysBack: Int
init(daysBack: Int, headerTypeChanged: @escaping ((MainSwitchableViewType) -> Void)) {
self.daysBack = daysBack
self.headerTypeChanged = headerTypeChanged
}
var body: some View {
VStack {
ZStack {
HeaderStatsView(fakeData: false, backDays: daysBack)
.opacity(currentViewIdx == 0 ? 1 : 0)
.padding([.leading, .trailing], -15)
.padding([.top, .bottom], 8)
.allowsHitTesting(false)
HeaderPercView(fakeData: false, backDays: daysBack, type: .circular)
.opacity(currentViewIdx == 1 ? 1 : 0)
.allowsHitTesting(false)
HeaderPercView(fakeData: false, backDays: daysBack, type: .text)
.opacity(currentViewIdx == 2 ? 1 : 0)
.allowsHitTesting(false)
switch viewType {
case .total:
HeaderStatsView(fakeData: false, backDays: daysBack)
.padding([.leading, .trailing], -15)
.padding([.top, .bottom], 8)
.allowsHitTesting(false)
case .percentageCircle:
HeaderPercView(fakeData: false, backDays: daysBack, type: .circular)
.allowsHitTesting(false)
case .percentage:
HeaderPercView(fakeData: false, backDays: daysBack, type: .text)
.allowsHitTesting(false)
}
VStack {
HStack {
Spacer()
@@ -60,16 +80,15 @@ struct SwitchableView: View {
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
.padding(.bottom, 30)
.onTapGesture {
currentViewIdx += 1
if currentViewIdx == 3 {
currentViewIdx = 0
}
viewType = viewType.next()
self.headerTypeChanged(viewType)
}
}
}
struct SwitchableView_Previews: PreviewProvider {
static var previews: some View {
SwitchableView(daysBack: 30)
SwitchableView(daysBack: 30, headerTypeChanged: { _ in
})
}
}