Files
Reflect/Shared/Views/BGView.swift
Trey t be84825aba Fix widget layout clipping and add comprehensive widget previews
- Fix LargeVotingView mood icons getting clipped at edges by using
  flexible HStack spacing with maxWidth: .infinity
- Fix VotingView medium layout with smaller icons and even distribution
- Add comprehensive #Preview macros for all widget states:
  - Vote widget: small/medium, voted/not voted, all mood states
  - Timeline widget: small/medium/large with various data states
- Reduce icon sizes and padding to fit within widget bounds
- Update accessibility labels and hints across views

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-24 09:53:40 -06:00

95 lines
2.8 KiB
Swift

//
// IconView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/20/22.
//
import SwiftUI
import SwiftData
struct BGViewItem: View {
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
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: Color) {
self.color = color
self.mood = mood
self.size = size
self.yRowPosition = yRowPosition
self.animate = animate
}
var body: some View {
FontAwesomeMoodImages.icon(forMood: mood)
.resizable()
.frame(width: size.width, height: size.height)
.foregroundColor(DefaultMoodTint.color(forMood: mood))
// .blur(radius: 3)
.opacity(0.1)
.accessibilityHidden(true)
}
}
struct BGView: View, Equatable {
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
var numAcross: Int
var numDown: Int
let iconSize = 35
init(screenSize: CGSize = CGSize(width: 393, height: 852)) {
numAcross = Int(screenSize.width) / iconSize
numDown = Int(screenSize.height) / iconSize
}
var randomMood: Mood? {
return Mood.allValues.randomElement()
}
var body: some View {
VStack {
ForEach(0...numDown, id: \.self) { row in
HStack {
ForEach(0...numAcross, id: \.self) { _ in
if let randomMood = randomMood {
BGViewItem(mood: randomMood,
size: .init(width: iconSize,height: iconSize),
animate: false,
yRowPosition: Float(row)/Float(numDown),
color: moodTint.color(forMood:randomMood))
}
}.frame(minWidth: 0, maxWidth: .infinity)
.padding([.trailing, .leading], 13.5)
}
.padding(.top, -9)
}
}
.padding(.top, -50)
}
static func == (lhs: BGView, rhs: BGView) -> Bool {
return true
}
}
#if !WIDGET_EXTENSION
struct BGView_Previews: PreviewProvider {
static var previews: some View {
BGView().modelContainer(DataController.shared.container)
.onAppear(perform: {
DataController.shared.populateMemory()
})
BGView()
.preferredColorScheme(.dark)
.modelContainer(DataController.shared.container)
}
}
#endif