-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
SheetActions.swift
78 lines (66 loc) · 3.34 KB
/
SheetActions.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
/// Common Actions used by CreateButtonActionSheet
struct PostAction: ActionSheetItem {
let handler: () -> Void
let source: String
private let action = "create_new_post"
func makeButton() -> ActionSheetButton {
let highlight: Bool = QuickStartTourGuide.shared.shouldSpotlight(.newpost)
return ActionSheetButton(title: NSLocalizedString("Blog post", comment: "Create new Blog Post button title"),
image: .gridicon(.posts),
identifier: "blogPostButton",
highlight: highlight,
action: {
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
handler()
})
}
}
struct PageAction: ActionSheetItem {
let handler: () -> Void
let source: String
private let action = "create_new_page"
func makeButton() -> ActionSheetButton {
let highlight: Bool = QuickStartTourGuide.shared.shouldSpotlight(.newPage)
return ActionSheetButton(title: NSLocalizedString("Site page", comment: "Create new Site Page button title"),
image: .gridicon(.pages),
identifier: "sitePageButton",
highlight: highlight,
action: {
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
handler()
})
}
}
struct StoryAction: ActionSheetItem {
private enum Constants {
enum Badge {
static let font = UIFont.preferredFont(forTextStyle: .caption1)
static let insets = UIEdgeInsets(top: 2, left: 8, bottom: 2, right: 8)
static let cornerRadius: CGFloat = 2
static let backgroundColor = UIColor.muriel(color: MurielColor(name: .red, shade: .shade50))
}
}
let handler: () -> Void
let source: String
private let action = "create_new_story"
func makeButton() -> ActionSheetButton {
return ActionSheetButton(title: NSLocalizedString("Story post", comment: "Create new Story button title"),
image: .gridicon(.story),
identifier: "storyButton",
action: {
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
handler()
})
}
static func newBadge(title: String) -> UIButton {
let badge = UIButton(type: .custom)
badge.translatesAutoresizingMaskIntoConstraints = false
badge.setTitle(title, for: .normal)
badge.titleLabel?.font = Constants.Badge.font
badge.contentEdgeInsets = Constants.Badge.insets
badge.layer.cornerRadius = Constants.Badge.cornerRadius
badge.isUserInteractionEnabled = false
badge.backgroundColor = Constants.Badge.backgroundColor
return badge
}
}