Files
Reflect/Shared/views/BGView.swift
Trey t 55bcb460ba create contentview view model
add background to content view
make contentview list split by year / month
test data will add 120 days instead of 25

closed #35
closed #36
2022-01-20 16:12:49 -06:00

78 lines
2.1 KiB
Swift

//
// IconView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/20/22.
//
import SwiftUI
struct BGViewItem: View {
let mood: Mood
let size: CGSize
var color: Color
let animate: Bool
let yRowPosition: Float
init(mood: Mood, size: CGSize, animate: Bool, yRowPosition: Float) {
color = mood.color
self.mood = mood
self.size = size
self.yRowPosition = yRowPosition
self.animate = animate
}
var body: some View {
Mood.allValues.randomElement()?.icon
.resizable()
.frame(width: size.width, height: size.height)
.foregroundColor(color)
// .blur(radius: 3)
.opacity(0.1)
}
}
struct BGView: View {
var numAcross: Int
var numDown: Int
let iconSize = 35
init() {
let screenWidth = UIScreen.main.bounds.width
numAcross = Int(screenWidth)/iconSize
let screenHeight = UIScreen.main.bounds.height
numDown = Int(screenHeight)/iconSize
}
var body: some View {
VStack {
ForEach(0...numDown, id: \.self) { row in
HStack {
ForEach(0...numAcross, id: \.self) { _ in
BGViewItem(mood: Mood.allValues.randomElement()!,
size: .init(width: iconSize,height: iconSize),
animate: false,
yRowPosition: Float(row)/Float(numDown))
}.frame(minWidth: 0, maxWidth: .infinity)
}
.padding(.top, -8)
}
}
.padding(.top, -50)
}
}
struct BGView_Previews: PreviewProvider {
static var previews: some View {
BGView().environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
.onAppear(perform: {
PersistenceController.shared.populateMemory()
})
BGView()
.preferredColorScheme(.dark)
.environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
}
}