Added some more normal calendar places, played with the day and calendar view
This commit is contained in:
@@ -7,20 +7,23 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
|
extension Color {
|
||||||
|
init(r: Double, g: Double, b: Double) {
|
||||||
|
self.init(red: r / 255, green: g / 255, blue: b / 255)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct CalendarView: View {
|
struct CalendarView: View {
|
||||||
var events: [TrashEvent]
|
var events: [TrashEvent]
|
||||||
let columns: [GridItem] = Array(repeating: .init(.adaptive(minimum: 50, maximum: 50)), count: 7)
|
let columns = [GridItem(), GridItem(), GridItem(), GridItem(), GridItem(), GridItem(), GridItem()]
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
VStack {
|
VStack {
|
||||||
let width: CGFloat = geometry.size.width / 8
|
let width = geometry.size.width / 7.5
|
||||||
LazyVGrid(columns: [adaptiveGridItem(width: width)], spacing: 0) {
|
LazyVGrid(columns: [adaptiveGridItem(width: width)], spacing: 0) {
|
||||||
ForEach(0..<events.count) { i in
|
ForEach(events) { event in
|
||||||
let event = events[i]
|
|
||||||
DayView(image: event.trash.image, dayOfTheWeek: "TBD", date: event.id, color: event.trash.color)
|
DayView(image: event.trash.image, dayOfTheWeek: "TBD", date: event.id, color: event.trash.color)
|
||||||
// Text(String(event.id))
|
.border(Color(r: 217, g: 185, b: 155), width: 1)
|
||||||
.frame(minWidth: 50, minHeight: 50)
|
|
||||||
.border(.black, width: 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
|
|||||||
@@ -16,20 +16,28 @@ struct DayView: View {
|
|||||||
var date: Int
|
var date: Int
|
||||||
var color: Color
|
var color: Color
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
ZStack {
|
ZStack {
|
||||||
Color.init(color)
|
Color.init(color)
|
||||||
.cornerRadius(10)
|
// .cornerRadius(10)
|
||||||
.scaledToFit()
|
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
Image(systemName: image)
|
|
||||||
.font(.caption)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
|
||||||
.padding(.trailing, 6)
|
|
||||||
.padding(.top, 30)
|
|
||||||
Text("\(date).")
|
Text("\(date).")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
VStack {
|
||||||
|
Spacer()
|
||||||
|
HStack(alignment: .bottom) {
|
||||||
|
Spacer()
|
||||||
|
Image(systemName: image)
|
||||||
|
// .padding([.bottom, .trailing])
|
||||||
|
.font(.caption)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.aspectRatio(1.0, contentMode: .fit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ struct MainView: View {
|
|||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
VStack {
|
VStack {
|
||||||
CalendarView(events: model.getTrashEvents())
|
CalendarView(events: model.getTrashEvents())
|
||||||
.padding()
|
// .padding()
|
||||||
let width: CGFloat = geometry.size.width / 2
|
let width: CGFloat = geometry.size.width / 2
|
||||||
LazyVGrid(columns: [adaptiveGridItem(width: width)], spacing: 0) {
|
LazyVGrid(columns: [adaptiveGridItem(width: width)], spacing: 0) {
|
||||||
DayView(image: "tree", dayOfTheWeek: "Mon", date: 31, color: .green)
|
DayView(image: "tree", dayOfTheWeek: "Mon", date: 31, color: .green)
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ struct TrashModel {
|
|||||||
Trash(type: "plastic", color: .orange, image: "waterbottle"),
|
Trash(type: "plastic", color: .orange, image: "waterbottle"),
|
||||||
Trash(type: "paper", color: .blue, image: "newspaper"),
|
Trash(type: "paper", color: .blue, image: "newspaper"),
|
||||||
Trash(type: "bio", color: .green, image: "tree"),
|
Trash(type: "bio", color: .green, image: "tree"),
|
||||||
Trash(type: "residual", color: .gray, image: "trash")
|
Trash(type: "residual", color: .gray, image: "trash"),
|
||||||
|
Trash(type: "none", color: .white, image: "")
|
||||||
]
|
]
|
||||||
|
|
||||||
self.trashEvents = []
|
self.trashEvents = []
|
||||||
@@ -80,8 +81,8 @@ struct TrashModel {
|
|||||||
self.trashEvents.append(
|
self.trashEvents.append(
|
||||||
TrashEvent(
|
TrashEvent(
|
||||||
id: i,
|
id: i,
|
||||||
trash: self.trashTypes[3],
|
trash: self.trashTypes[4],
|
||||||
date: Calendar.current.date(byAdding: .day, value: 6 + 7 + 7*i, to: Date())!
|
date: Calendar.current.date(byAdding: .day, value: 3 + 7 + 7*i, to: Date())!
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user