template sharing

This commit is contained in:
Trey t
2022-02-26 16:16:40 -06:00
parent 4b7c64cbc6
commit 7bcd9a3d13
4 changed files with 150 additions and 92 deletions

View File

@@ -20,6 +20,8 @@ struct MonthTotalTemplate: View, SharingTemplate {
private var month = Calendar.current.dateComponents([.month], from: Date()).month!
@State var showSharingTemplate = false
@StateObject private var shareImage = StupidAssShareObservableObject()
@Environment(\.presentationMode) var presentationMode
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -68,7 +70,7 @@ struct MonthTotalTemplate: View, SharingTemplate {
}
var image: UIImage {
let image = shareView.snapshot()
let image = shareView.asImage(size: CGSize(width: 666, height: 1190))
return image
}
@@ -106,6 +108,23 @@ struct MonthTotalTemplate: View, SharingTemplate {
.frame(maxWidth: .infinity, alignment: .center)
.padding()
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
Circle()
.frame(minWidth: 10, idealWidth: 70, maxWidth: 100, minHeight: 10, idealHeight: 70, maxHeight: 100)
.aspectRatio(contentMode: .fit)
.foregroundColor(moodTint.color(forMood: mood))
.overlay(
mood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.white)
.padding(9)
)
}
}
.padding()
VStack {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(moodEntries) { entry in
@@ -119,19 +138,23 @@ struct MonthTotalTemplate: View, SharingTemplate {
.padding()
circularViews
.padding([.trailing, .leading, .top])
.padding()
}
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
.padding()
}
var mainView: some View {
VStack {
shareView
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
Spacer()
HStack(alignment: .center) {
Button(action: {
showSharingTemplate = true
let _image = self.image
self.shareImage.showFuckingSheet = true
self.shareImage.fuckingWrappedShrable = _image
}, label: {
Text("Share")
.font(.title)
@@ -139,6 +162,11 @@ struct MonthTotalTemplate: View, SharingTemplate {
.foregroundColor(Color.white)
.padding(.top, 20)
})
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
if let uiImage = self.shareImage.fuckingWrappedShrable {
ShareSheet(photo: uiImage)
}
}
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
@@ -161,18 +189,15 @@ struct MonthTotalTemplate: View, SharingTemplate {
.padding(.leading, -5)
}
.padding([.leading, .trailing], -20)
}.sheet(isPresented: $showSharingTemplate) {
ActivityViewController(activityItems: [self.image])
}
}
var body: some View {
if isPreview {
preview
.padding([.leading, .trailing], -20)
shareView
.scaleEffect(2)
} else {
mainView
.padding([.leading, .trailing, .top])
}
}
}
@@ -182,5 +207,7 @@ struct MonthTotalTemplate_Previews: PreviewProvider {
MonthTotalTemplate(isPreview: true, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true)
MonthTotalTemplate(isPreview: false, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true)
MonthTotalTemplate(isPreview: false, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true).shareView
}
}