Widget Extension Fixes: - Create standalone WidgetDataProvider for widget data isolation - Add WIDGET_EXTENSION compiler flag for conditional compilation - Fix DataController references in widget-shared files - Sync widget version numbers with main app (23, 1.0.2) - Add WidgetBackground color to asset catalog Warning Resolutions: - Fix UIScreen.main deprecation in BGView and SharingListView - Fix Text '+' concatenation deprecation in PurchaseButtonView and SettingsTabView - Fix exhaustive switch in BiometricAuthManager (add .none case) - Fix var to let in ExportService (3 instances) - Fix unused result warning in NoteEditorView - Fix ForEach duplicate ID warnings in MonthView and YearView Code Quality Improvements: - Wrap bypassSubscription in #if DEBUG for security - Rename StupidAssCustomWidgetObservableObject to CustomWidgetStateViewModel - Add @MainActor to IconViewModel - Replace fatalError with graceful fallback in SharedModelContainer - Add [weak self] to closures in DayViewViewModel - Add OSLog-based AppLogger for production logging - Add ImageCache with NSCache for memory efficiency - Add AccessibilityHelpers with Reduce Motion support - Create DataControllerProtocol for dependency injection - Update .gitignore with secrets exclusions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
163 lines
6.4 KiB
Swift
163 lines
6.4 KiB
Swift
//
|
|
// SharingView.swift
|
|
// Feels (iOS)
|
|
//
|
|
// Created by Trey Tartt on 2/6/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WrappedSharable: Hashable, Equatable {
|
|
static func == (lhs: WrappedSharable, rhs: WrappedSharable) -> Bool {
|
|
lhs.id == rhs.id && lhs.description == rhs.description
|
|
}
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(id)
|
|
}
|
|
|
|
let id = UUID()
|
|
let preview: AnyView
|
|
let destination: AnyView
|
|
let description: String
|
|
}
|
|
|
|
struct SharingListView: View {
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
|
|
|
|
class ShareStateViewModel: ObservableObject {
|
|
@Published var selectedItem: WrappedSharable? = nil
|
|
@Published var showSheet = false
|
|
}
|
|
|
|
@StateObject private var selectedShare = ShareStateViewModel()
|
|
var sharebleItems = [WrappedSharable]()
|
|
|
|
@MainActor
|
|
init() {
|
|
self.sharebleItems = [
|
|
WrappedSharable(preview: AnyView(
|
|
AllMoodsTotalTemplate(isPreview: true,
|
|
startDate: DataController.shared.earliestEntry?.forDate ?? Date(),
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
),destination: AnyView(
|
|
AllMoodsTotalTemplate(isPreview: false,
|
|
startDate: DataController.shared.earliestEntry?.forDate ?? Date(),
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
),description: AllMoodsTotalTemplate.description),
|
|
//////////////////////////////////////////////////////////
|
|
WrappedSharable(preview: AnyView(
|
|
CurrentStreakTemplate(isPreview: true,
|
|
startDate: Calendar.current.date(byAdding: .day, value: -10, to: Date())!,
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
), destination: AnyView(
|
|
CurrentStreakTemplate(isPreview: false,
|
|
startDate: Calendar.current.date(byAdding: .day, value: -10, to: Date())!,
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
), description: CurrentStreakTemplate.description),
|
|
//////////////////////////////////////////////////////////
|
|
WrappedSharable(preview: AnyView(
|
|
LongestStreakTemplate(isPreview: true,
|
|
startDate: DataController.shared.earliestEntry?.forDate ?? Date(),
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
), destination: AnyView(
|
|
LongestStreakTemplate(isPreview: false,
|
|
startDate: DataController.shared.earliestEntry?.forDate ?? Date(),
|
|
endDate: Date(),
|
|
fakeData: false)
|
|
), description: LongestStreakTemplate.description),
|
|
//////////////////////////////////////////////////////////
|
|
WrappedSharable(preview: AnyView(
|
|
MonthTotalTemplate(isPreview: true,
|
|
startDate: Date().startOfMonth,
|
|
endDate: Date().endOfMonth,
|
|
fakeData: false)
|
|
), destination: AnyView(
|
|
MonthTotalTemplate(isPreview: false,
|
|
startDate: Date().startOfMonth,
|
|
endDate: Date().endOfMonth,
|
|
fakeData: false)
|
|
), description: MonthTotalTemplate.description)
|
|
//////////////////////////////////////////////////////////
|
|
]
|
|
}
|
|
|
|
|
|
|
|
func didDismiss() {
|
|
selectedShare.showSheet = false
|
|
selectedShare.selectedItem = nil
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
ScrollView {
|
|
ForEach(sharebleItems, id: \.self) { item in
|
|
Button(action: {
|
|
selectedShare.selectedItem = item
|
|
selectedShare.showSheet = true
|
|
}, label: {
|
|
ZStack {
|
|
theme.currentTheme.secondaryBGColor
|
|
|
|
item.preview
|
|
.frame(height: 88)
|
|
|
|
VStack {
|
|
Spacer()
|
|
Text(item.description)
|
|
.font(.title)
|
|
.foregroundColor(textColor)
|
|
.fontWeight(.bold)
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
.frame(height: 44)
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
.opacity(0.9)
|
|
}
|
|
}
|
|
.frame(height: 88)
|
|
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
|
.scaledToFill()
|
|
.clipped()
|
|
.contentShape(Rectangle())
|
|
.padding([.leading, .trailing])
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
.padding([.top, .bottom])
|
|
.background(
|
|
theme.currentTheme.bg
|
|
.edgesIgnoringSafeArea(.top)
|
|
)
|
|
.sheet(isPresented: $selectedShare.showSheet,
|
|
onDismiss: didDismiss) {
|
|
selectedShare.selectedItem?.destination
|
|
}
|
|
}
|
|
|
|
func share(image: UIImage) {
|
|
|
|
}
|
|
}
|
|
|
|
struct SharingView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
SharingListView()
|
|
|
|
SharingListView()
|
|
.preferredColorScheme(.dark)
|
|
}
|
|
}
|
|
}
|