-
Notifications
You must be signed in to change notification settings - Fork 134
/
EditFolderView.swift
102 lines (97 loc) · 4.19 KB
/
EditFolderView.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import SwiftUI
struct EditFolderView: View {
@EnvironmentObject var theme: Theme
@ObservedObject var model: FolderModel
var dismissAction: (Bool) -> Void
@State var showingDeleteConfirmation = false
var body: some View {
NavigationView {
VStack(alignment: .leading) {
Group {
Text(L10n.name.localizedUppercase)
.textStyle(SecondaryText())
.font(.subheadline)
.padding(.bottom, -8)
.padding(.top, 30)
TextField("", text: $model.name)
.onChange(of: model.name, perform: model.validateFolderName)
.themedTextField()
}
.padding(.bottom, 10)
.padding([.leading, .trailing], 16)
VStack(alignment: .leading, spacing: 20) {
Text(L10n.color.localizedUppercase)
.textStyle(SecondaryText())
.font(.subheadline)
.padding(.bottom, -14)
.padding([.leading, .trailing], 16)
ThemedDivider()
ColorSelectRow(model: model)
.padding([.leading, .trailing], 16)
}
.padding(.vertical, 10)
ThemedDivider()
.padding(.bottom, 16)
VStack(alignment: .leading, spacing: 15) {
ThemedDivider()
Button {
showingDeleteConfirmation = true
Analytics.track(.folderEditDeleteButtonTapped)
} label: {
Group {
Image("delete")
Text(L10n.folderDelete)
.frame(maxWidth: .infinity, alignment: .leading)
}
.foregroundColor(ThemeColor.support05(for: theme.activeTheme).color)
.padding(.leading, 16)
}
.alert(isPresented: $showingDeleteConfirmation) {
Alert(
title: Text(L10n.folderDeletePromptTitle),
message: Text(L10n.folderDeletePromptMsg),
primaryButton: .destructive(Text(L10n.delete)) {
model.deleteFolder()
Analytics.track(.folderDeleted)
dismissAction(true)
},
secondaryButton: .cancel()
)
}
ThemedDivider()
}
.padding(.top, 10)
Spacer()
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
dismissAction(false)
} label: {
Image("close")
.foregroundColor(ThemeColor.secondaryIcon01(for: theme.activeTheme).color)
}
.accessibilityLabel(L10n.close)
}
}
.onAppear {
Analytics.track(.folderEditShown)
}
.onDisappear {
NotificationCenter.postOnMainThread(notification: Constants.Notifications.folderChanged, object: model.folderUuid)
NotificationCenter.postOnMainThread(notification: Constants.Notifications.folderEdited, object: model.folderUuid)
Analytics.track(.folderEditDismissed, properties: ["did_change_name": model.didChangeName, "did_change_color": model.didChangeColor])
}
.applyDefaultThemeOptions()
.navigationTitle(L10n.folderEdit)
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
struct EditFolderView_Previews: PreviewProvider {
static var previews: some View {
EditFolderView(model: FolderModel(), dismissAction: { _ in })
.environmentObject(Theme(previewTheme: .light))
.previewOnAllDevices()
}
}