closed #74
If looking at totals roll up should be totals, if percentage then percentages should show
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user