106 lines
3.6 KiB
Swift
106 lines
3.6 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
|
|
}
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(id)
|
|
}
|
|
|
|
let id = UUID()
|
|
let preview: AnyView
|
|
let destination: AnyView
|
|
let description: String
|
|
}
|
|
|
|
struct SharingView: View {
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
|
|
@State private var selectedShare: WrappedSharable?
|
|
@State private var showSharingTemplate = false
|
|
|
|
let sharebleItems: [WrappedSharable] = [
|
|
WrappedSharable(preview: AnyView(
|
|
AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date())
|
|
),destination: AnyView(
|
|
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date())
|
|
),description: AllMoodsTotalTemplate.description),
|
|
|
|
WrappedSharable(preview: AnyView(
|
|
CurrentStreakTemplate(isPreview: true, startDate: Date(), endDate: Date())
|
|
), destination: AnyView(
|
|
CurrentStreakTemplate(isPreview: false, startDate: Date(), endDate: Date())
|
|
), description: CurrentStreakTemplate.description),
|
|
|
|
WrappedSharable(preview: AnyView(
|
|
LongestStreakTemplate(isPreview: true, startDate: Date(), endDate: Date())
|
|
), destination: AnyView(
|
|
LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date())
|
|
), description: LongestStreakTemplate.description),
|
|
|
|
WrappedSharable(preview: AnyView(
|
|
MonthTotalTemplate(isPreview: true, startDate: Date(), endDate: Date())
|
|
), destination: AnyView(
|
|
MonthTotalTemplate(isPreview: false, startDate: Date(), endDate: Date())
|
|
), description: MonthTotalTemplate.description),
|
|
|
|
WrappedSharable(preview: AnyView(
|
|
WeekTotalTemplate(isPreview: true, startDate: Date(), endDate: Date())
|
|
), destination: AnyView(
|
|
WeekTotalTemplate(isPreview: false, startDate: Date(), endDate: Date())
|
|
), description: WeekTotalTemplate.description)
|
|
]
|
|
|
|
func didDismiss() {
|
|
showSharingTemplate = false
|
|
}
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
ForEach(sharebleItems, id: \.self) { item in
|
|
ZStack {
|
|
Color(theme.currentTheme.secondaryBGColor)
|
|
|
|
item.preview
|
|
.opacity(0.5)
|
|
|
|
VStack {
|
|
Spacer()
|
|
Text(item.description)
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
.background(
|
|
Color.white
|
|
)
|
|
.frame(minHeight: 22, maxHeight: 22)
|
|
}
|
|
}
|
|
.frame(minHeight: 88, maxHeight: 88)
|
|
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
|
.onTapGesture ( perform: {
|
|
selectedShare = item
|
|
showSharingTemplate = true
|
|
})
|
|
}
|
|
.padding()
|
|
}.sheet(isPresented: $showSharingTemplate,
|
|
onDismiss: didDismiss) {
|
|
selectedShare?.destination
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SharingView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SharingView()
|
|
}
|
|
}
|