WIP - Sharing
This commit is contained in:
@@ -66,7 +66,7 @@ struct ContentView: View {
|
||||
Label(String(localized: "content_view_tab_filter"), systemImage: "calendar.circle")
|
||||
}
|
||||
|
||||
SharingView()
|
||||
SharingListView()
|
||||
.tabItem {
|
||||
Label(String(localized: "content_view_tab_share"), systemImage: "square.and.arrow.up")
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// ShareButtonview.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 2/8/22.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ShareButtonview: View, Equatable {
|
||||
static func == (lhs: ShareButtonview, rhs: ShareButtonview) -> Bool {
|
||||
lhs.image == rhs.image
|
||||
}
|
||||
|
||||
@State private var showSheet = false
|
||||
@State var image: UIImage? {
|
||||
didSet {
|
||||
showSheet = true
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
showSheet = true
|
||||
}, label: {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.foregroundColor(.black)
|
||||
})
|
||||
|
||||
if showSheet {
|
||||
if let image = image {
|
||||
ActivityViewController(activityItems: [image])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ShareButtonview_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ShareButtonview()
|
||||
}
|
||||
}
|
||||
151
Shared/views/SharingListView.swift
Normal file
151
Shared/views/SharingListView.swift
Normal file
@@ -0,0 +1,151 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
class StupidAssObservableObject: ObservableObject {
|
||||
@Published var fuckingWrappedShrable: WrappedSharable? = nil
|
||||
@Published var showFuckingSheet = false
|
||||
}
|
||||
|
||||
@StateObject private var selectedShare = StupidAssObservableObject()
|
||||
|
||||
let sharebleItems: [WrappedSharable] = [
|
||||
WrappedSharable(preview: AnyView(
|
||||
AllMoodsTotalTemplate(isPreview: true,
|
||||
startDate: PersistenceController.shared.earliestEntry?.forDate ?? Date(),
|
||||
endDate: Date(),
|
||||
fakeData: false)
|
||||
),destination: AnyView(
|
||||
AllMoodsTotalTemplate(isPreview: false,
|
||||
startDate: PersistenceController.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: PersistenceController.shared.earliestEntry?.forDate ?? Date(),
|
||||
endDate: Date(),
|
||||
fakeData: false)
|
||||
), destination: AnyView(
|
||||
LongestStreakTemplate(isPreview: false,
|
||||
startDate: PersistenceController.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.showFuckingSheet = false
|
||||
selectedShare.fuckingWrappedShrable = nil
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(String(format: String(localized: "Share your shit")))
|
||||
.font(.title)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.padding([.top, .leading])
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
ScrollView {
|
||||
ForEach(sharebleItems, id: \.self) { item in
|
||||
Button(action: {
|
||||
selectedShare.fuckingWrappedShrable = item
|
||||
selectedShare.showFuckingSheet = true
|
||||
}, label: {
|
||||
ZStack {
|
||||
Color(theme.currentTheme.secondaryBGColor)
|
||||
|
||||
item.preview
|
||||
.frame(height: 88)
|
||||
|
||||
VStack {
|
||||
Spacer()
|
||||
Text(item.description)
|
||||
.font(.title)
|
||||
.foregroundColor(Color(UIColor.label))
|
||||
.fontWeight(.bold)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.frame(height: 44)
|
||||
.background(
|
||||
Color(UIColor.secondarySystemBackground)
|
||||
)
|
||||
.opacity(0.9)
|
||||
}
|
||||
}
|
||||
.frame(height: 88)
|
||||
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
||||
.scaledToFill()
|
||||
.clipped()
|
||||
.contentShape(Path(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 88)))
|
||||
.padding([.leading, .trailing])
|
||||
})
|
||||
}
|
||||
|
||||
}.background(
|
||||
theme.currentTheme.bg
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
)
|
||||
}
|
||||
.sheet(isPresented: $selectedShare.showFuckingSheet,
|
||||
onDismiss: didDismiss) {
|
||||
selectedShare.fuckingWrappedShrable?.destination
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SharingView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SharingListView()
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user