add circular type to main view top small roll up header thingy

This commit is contained in:
Trey t
2022-02-06 14:25:11 -06:00
parent 3c6adce544
commit 9ed803d9cf
2 changed files with 48 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ import Charts
struct ContentViewConstants { struct ContentViewConstants {
static let maxHeaderHeight = 200.0 static let maxHeaderHeight = 200.0
static let minHeaderHeight = 88.0 static let minHeaderHeight = 120.0
} }
struct ContentView: View { struct ContentView: View {
@@ -345,7 +345,7 @@ struct ContentView: View {
.opacity(headerOpacity) .opacity(headerOpacity)
VStack { VStack {
SmallRollUpHeaderView(fakeData: false, backDays: 30) SmallRollUpHeaderView(fakeData: false, backDays: 30, type: .circular)
.background( .background(
Color(theme.currentTheme.secondaryBGColor) Color(theme.currentTheme.secondaryBGColor)
) )

View File

@@ -7,11 +7,18 @@
import SwiftUI import SwiftUI
enum SmallRollUpHeaderViewType {
case text
case circular
}
struct SmallRollUpHeaderView: View { struct SmallRollUpHeaderView: View {
var entries = [(Mood, Int)]() var entries = [(Mood, Int)]()
let backDays: Int let backDays: Int
let type: SmallRollUpHeaderViewType
init(fakeData: Bool, backDays: Int) { init(fakeData: Bool, backDays: Int, type: SmallRollUpHeaderViewType) {
self.type = type
self.backDays = backDays self.backDays = backDays
var moodEntries: [MoodEntry]? var moodEntries: [MoodEntry]?
@@ -36,29 +43,56 @@ struct SmallRollUpHeaderView: View {
}) })
} }
private var textViews: some View {
HStack {
ForEach(entries, id: \.0) { (mood, value) in
Text(String(value))
.font(.title)
.fontWeight(.bold)
.foregroundColor(mood.color)
.frame(maxWidth: .infinity)
}
}
}
private var circularViews: some View {
HStack {
ForEach(entries, id: \.0) { (mood, value) in
Text(String(value))
.font(.title)
.fontWeight(.bold)
.frame(maxWidth: .infinity)
.padding()
.background(Circle().fill(mood.color))
.foregroundColor(Color(UIColor.white))
}
}
}
var body: some View { var body: some View {
VStack { VStack {
HStack { switch self.type {
ForEach(entries, id: \.0) { (mood, value) in case .text:
Text(String(value)) textViews
.font(.title) .padding([.trailing, .leading, .top])
.fontWeight(.bold) case .circular:
.foregroundColor(mood.color) circularViews
.frame(maxWidth: .infinity) .padding([.trailing, .leading, .top])
}
} }
Text(String(format: String(localized: "content_view_header_title"), self.backDays)) Text(String(format: String(localized: "content_view_header_title"), self.backDays))
.font(.body) .font(.body)
.foregroundColor(Color(UIColor.systemGray)) .foregroundColor(Color(UIColor.systemGray))
.frame(maxWidth: .infinity, alignment: .center) .frame(maxWidth: .infinity, alignment: .center)
.padding(.top, 2) .padding(.top, 1)
} }
} }
} }
struct SmallHeaderView_Previews: PreviewProvider { struct SmallHeaderView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
SmallRollUpHeaderView(fakeData: true, backDays: 30) SmallRollUpHeaderView(fakeData: true, backDays: 30, type: .text)
SmallRollUpHeaderView(fakeData: true, backDays: 30, type: .circular)
} }
} }