-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDreamDiarySheetView.swift
72 lines (67 loc) · 2.42 KB
/
DreamDiarySheetView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// DreamDiarySheetView.swift
// Lucify (iOS)
//
// Created by Patrick Elfert on 07.06.22.
//
import SwiftUI
struct DreamDiarySheetView: View {
@Environment(\.dismiss) var dismiss
@State var diaryEntry: DiaryEntryModel
@State var showingAlert = false
var onSave: (DiaryEntryModel) -> Void
var onDelete: ((DiaryEntryModel) -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .firstTextBaseline) {
Text("Record dream")
.font(Font.largeTitle.weight(.bold))
if onDelete != nil {
Image(systemName: "trash.circle.fill")
.font(.title)
.padding(.leading, 10)
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .red)
.onTapGesture {
showingAlert = true
}
}
}.padding([.top, .leading])
.alert("Do you really want to delete this Dream?", isPresented: $showingAlert) {
Button("Cancel", role: .cancel) {}
Button("Ok", role: .destructive) {
onDelete!(diaryEntry)
dismiss()
}
}
Form {
Section {
TextField("Title", text: $diaryEntry.title)
}
Section {
TextEditorWithPlaceholder(text: $diaryEntry.description)
}
Section {
Toggle("Lucid", isOn: $diaryEntry.isLucid).tint(Primary)
}
}
Button(action: {
onSave(diaryEntry)
dismiss()
}) {
HStack(alignment: .firstTextBaseline) {
Text("Save")
Image(systemName: "cloud.moon.fill")
}.frame(maxWidth: .infinity, maxHeight: 50)
}
.background(Primary)
.cornerRadius(5)
.foregroundColor(.primary).padding()
}
}
}
struct DreamDiarySheetView_Previews: PreviewProvider {
static var previews: some View {
DreamDiarySheetView(diaryEntry: DiaryEntryModel(date: Date.now, title: "test", description: "testdc", isLucid: true), onSave: { _ in }, onDelete: { _ in })
}
}