made bgview equatable so it doesn't get redrawn each time a sheet is shown add more string to localization fill in missing data on launch ... incase they have bgfetch turned off
82 lines
2.2 KiB
Swift
82 lines
2.2 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, Equatable {
|
|
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)
|
|
}
|
|
|
|
static func == (lhs: BGView, rhs: BGView) -> Bool {
|
|
return true
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|