create tapable header that will switch between bar chart and percentage
WIP - add secondary header for 7 days closed #21
This commit is contained in:
51
Shared/views/SwitchableView.swift
Normal file
51
Shared/views/SwitchableView.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// SwitchableView.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 1/30/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
|
||||
struct SwitchableView: View {
|
||||
@State var currentViewIdx = 0
|
||||
|
||||
let daysBack: Int
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ZStack {
|
||||
HeaderStatsView(fakeData: false, backDays: daysBack)
|
||||
.opacity(currentViewIdx == 0 ? 1 : 0)
|
||||
|
||||
HeaderPercView(fakeData: false, backDays: daysBack)
|
||||
.opacity(currentViewIdx == 1 ? 1 : 0)
|
||||
}
|
||||
.padding([.top, .bottom], -7)
|
||||
|
||||
Text(String(format: String(localized: "content_view_header_title"), daysBack))
|
||||
.font(.body)
|
||||
.foregroundColor(Color(UIColor.systemGray))
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.bottom, 15)
|
||||
}
|
||||
.background(
|
||||
Color(UIColor.systemBackground)
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
||||
.padding()
|
||||
.onTapGesture {
|
||||
currentViewIdx += 1
|
||||
if currentViewIdx == 2 {
|
||||
currentViewIdx = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SwitchableView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SwitchableView(daysBack: 30)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user