-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathWPStyleGuide+Notifications.swift
More file actions
316 lines (260 loc) · 14.2 KB
/
WPStyleGuide+Notifications.swift
File metadata and controls
316 lines (260 loc) · 14.2 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// FIXME: This does not belong here, see https://github.com/wordpress-mobile/WordPress-iOS/pull/24297
import Foundation
import Gridicons
import UIKit
import WordPressShared
import WordPressSharedUI
import WordPressKit // FIXME: Here just for the NSMutableParagraphStyle custom init
import WordPressUI
extension WPStyleGuide {
public struct Notifications {
// MARK: - Styles Used by NotificationsViewController
//
// ListTableViewCell
public static let unreadIndicatorColor = UIAppColor.primaryLight
// Notification cells
public static let noticonFont = UIFont(name: "Noticons", size: 16)
public static let noticonReadColor = UIColor.systemGray
// Notification undo overlay
public static let noteUndoBackgroundColor = UIAppColor.error
public static let noteUndoTextColor = UIColor.white
public static let noteUndoTextFont = subjectRegularFont
// Subject Text
public static var subjectRegularStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: subjectParagraph,
.font: subjectRegularFont,
.foregroundColor: subjectTextColor ]
}
public static var subjectSemiBoldStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: subjectParagraph,
.font: subjectSemiBoldFont ]
}
public static var subjectItalicsStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: subjectParagraph,
.font: subjectItalicsFont ]
}
public static var subjectNoticonStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: subjectParagraph,
.font: subjectNoticonFont,
.foregroundColor: subjectNoticonColor ]
}
public static let subjectQuotedStyle = blockQuotedStyle
// Subject Snippet
public static var snippetRegularStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: snippetParagraph,
.font: subjectRegularFont,
.foregroundColor: snippetColor ]
}
public static var headerDetailsRegularStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: snippetHeaderParagraph,
.font: headerDetailsRegularFont,
.foregroundColor: headerDetailsColor
]
}
// MARK: - Styles used by NotificationDetailsViewController
//
// Header
public static let headerTitleColor = blockTextColor
public static let headerTitleBoldFont = blockBoldFont
public static let headerDetailsColor = UIAppColor.primary
public static let headerDetailsRegularFont = blockRegularFont
public static var headerTitleRegularStyle: [NSAttributedString.Key: Any] {
return [.font: headerTitleRegularFont,
.foregroundColor: headerTitleColor]
}
public static var headerTitleBoldStyle: [NSAttributedString.Key: Any] {
return [.font: headerTitleBoldFont,
.foregroundColor: headerTitleColor]
}
public static var headerTitleContextStyle: [NSAttributedString.Key: Any] {
return [.font: headerTitleItalicsFont,
.foregroundColor: headerTitleContextColor]
}
// Footer
public static var footerRegularStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: blockParagraph,
.font: blockRegularFont,
.foregroundColor: footerTextColor]
}
// Badges
public static let badgeBackgroundColor = UIColor.clear
public static let badgeLinkColor = blockLinkColor
public static let badgeTextColor = blockTextColor
public static let badgeQuotedColor = blockQuotedColor
public static let badgeRegularFont = UIFont.preferredFont(forTextStyle: .body)
public static let badgeBoldFont = badgeRegularFont.semibold()
public static let badgeItalicsFont = badgeRegularFont.italic()
public static let badgeTitleFont = WPStyleGuide.serifFontForTextStyle(.title1)
public static let badgeTitleBoldFont = badgeTitleFont.semibold()
public static let badgeTitleItalicsFont = badgeTitleFont.italic()
public static var badgeRegularStyle: [NSAttributedString.Key: Any] {
badgeStyle(withFont: badgeRegularFont)
}
public static var badgeBoldStyle: [NSAttributedString.Key: Any] {
badgeStyle(withFont: badgeBoldFont)
}
public static var badgeItalicsStyle: [NSAttributedString.Key: Any] {
badgeStyle(withFont: badgeItalicsFont)
}
public static var badgeQuotedStyle: [NSAttributedString.Key: Any] {
badgeStyle(withFont: badgeItalicsFont, color: badgeQuotedColor)
}
public static let badgeTitleStyle: [NSAttributedString.Key: Any] = badgeStyle(withFont: badgeTitleFont)
public static var badgeTitleBoldStyle: [NSAttributedString.Key: Any] = badgeStyle(withFont: badgeTitleBoldFont)
public static var badgeTitleItalicsStyle: [NSAttributedString.Key: Any] = badgeStyle(withFont: badgeTitleItalicsFont)
public static var badgeTitleQuotedStyle: [NSAttributedString.Key: Any] = badgeStyle(withFont: badgeTitleItalicsFont, color: badgeQuotedColor)
private static func badgeStyle(withFont font: UIFont, color: UIColor = badgeTextColor) -> [NSAttributedString.Key: Any] {
return [.paragraphStyle: badgeParagraph, .font: font, .foregroundColor: color ]
}
// Blocks
public static let contentBlockRegularFont = WPFontManager.notoRegularFont(ofSize: blockFontSize)
public static let contentBlockBoldFont = WPFontManager.notoBoldFont(ofSize: blockFontSize)
public static let contentBlockItalicFont = WPFontManager.notoItalicFont(ofSize: blockFontSize)
public static let blockRegularFont = WPFontManager.systemRegularFont(ofSize: blockFontSize)
public static let blockBoldFont = WPFontManager.systemSemiBoldFont(ofSize: blockFontSize)
public static let blockTextColor = UIColor.label
public static let blockQuotedColor = UIAppColor.neutral
public static let blockBackgroundColor = UIColor.secondarySystemGroupedBackground
public static let blockLinkColor = UIAppColor.primary
public static let blockSeparatorColor = UIColor.separator
public static var contentBlockRegularStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: contentBlockParagraph,
.font: contentBlockRegularFont,
.foregroundColor: blockTextColor ]
}
public static var contentBlockBoldStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: contentBlockParagraph,
.font: contentBlockBoldFont,
.foregroundColor: blockTextColor ]
}
public static var contentBlockQuotedStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: contentBlockParagraph,
.font: contentBlockItalicFont,
.foregroundColor: blockQuotedColor ]
}
public static var contentBlockMatchStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: contentBlockParagraph,
.font: contentBlockRegularFont,
.foregroundColor: blockLinkColor ]
}
public static var blockQuotedStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: blockParagraph,
.font: blockItalicsFont,
.foregroundColor: blockQuotedColor ]
}
public static var blockNoticonStyle: [NSAttributedString.Key: Any] {
return [.paragraphStyle: blockParagraph,
.font: blockNoticonFont,
.foregroundColor: blockNoticonColor ]
}
// RichText Helpers
public static func blockBackgroundColorForRichText(_ isBadge: Bool) -> UIColor {
return isBadge ? badgeBackgroundColor : blockBackgroundColor
}
// User Cell Helpers
public static func configureFollowButton(_ button: UIButton) {
// General
button.naturalContentHorizontalAlignment = .leading
button.backgroundColor = .clear
button.titleLabel?.font = WPStyleGuide.subtitleFont()
// Color(s)
let normalColor = UIAppColor.neutral(.shade50)
let highlightedColor = UIAppColor.neutral(.shade40)
let selectedColor = UIAppColor.success
button.setTitleColor(normalColor, for: .normal)
button.setTitleColor(selectedColor, for: .selected)
button.setTitleColor(highlightedColor, for: .highlighted)
// Image(s)
let side = WPStyleGuide.fontSizeForTextStyle(.subheadline)
let size = CGSize(width: side, height: side)
let followIcon = UIImage.gridicon(.readerFollow, size: size)
let followingIcon = UIImage.gridicon(.readerFollowing, size: size)
button.setImage(followIcon.imageWithTintColor(normalColor), for: .normal)
button.setImage(followingIcon.imageWithTintColor(selectedColor), for: .selected)
button.setImage(followingIcon.imageWithTintColor(highlightedColor), for: .highlighted)
button.imageEdgeInsets = UIEdgeInsets(top: 1, left: -4, bottom: 0, right: -4)
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 0)
// Strings
let normalText = NSLocalizedString("notifications.button.subscribe", value: "Subscribe", comment: "Prompt to subscribe to a blog.")
let selectedText = NSLocalizedString("notifications.button.subscribed", value: "Subscribed", comment: "User is subscribed to the blog.")
button.setTitle(normalText, for: .normal)
button.setTitle(selectedText, for: .selected)
button.setTitle(selectedText, for: .highlighted)
// Default accessibility label and hint.
button.accessibilityLabel = normalText
button.accessibilityHint = NSLocalizedString("notifications.button.subscribedHint", value: "Subscribes to the blog.", comment: "VoiceOver accessibility hint, informing the user the button can be used to subscribe to a blog.")
}
// MARK: - Constants
//
public static let subjectNoticonSize = UIDevice.isPad() ? CGFloat(15) : CGFloat(14)
public static let subjectLineSize = UIDevice.isPad() ? CGFloat(24) : CGFloat(18)
public static let snippetLineSize = subjectLineSize
public static let blockFontSize = UIDevice.isPad() ? CGFloat(16) : CGFloat(14)
public static let blockLineSize = UIDevice.isPad() ? CGFloat(24) : CGFloat(20)
public static let contentBlockLineSize = UIDevice.isPad() ? CGFloat(24) : CGFloat(21)
// MARK: - Private Propreties
//
// ParagraphStyle's
fileprivate static let subjectParagraph = NSMutableParagraphStyle(
minLineHeight: subjectLineSize, lineBreakMode: .byWordWrapping, alignment: .natural
)
fileprivate static let snippetParagraph = NSMutableParagraphStyle(
minLineHeight: snippetLineSize, lineBreakMode: .byWordWrapping, alignment: .natural
)
fileprivate static let snippetHeaderParagraph = NSMutableParagraphStyle(
minLineHeight: snippetLineSize, lineBreakMode: .byTruncatingTail, alignment: .natural
)
fileprivate static let blockParagraph = NSMutableParagraphStyle(
minLineHeight: blockLineSize, lineBreakMode: .byWordWrapping, alignment: .natural
)
fileprivate static let contentBlockParagraph = NSMutableParagraphStyle(
minLineHeight: contentBlockLineSize, lineBreakMode: .byWordWrapping, alignment: .natural
)
fileprivate static let badgeParagraph = NSMutableParagraphStyle(
minLineHeight: blockLineSize, lineBreakMode: .byWordWrapping, alignment: .center
)
// Colors
fileprivate static let subjectTextColor = UIColor.label
fileprivate static let subjectNoticonColor = noticonReadColor
fileprivate static let footerTextColor = UIColor.secondaryLabel
fileprivate static let blockNoticonColor = UIAppColor.neutral
fileprivate static let snippetColor = UIAppColor.neutral
fileprivate static let headerTitleContextColor = UIAppColor.primary
// Fonts
fileprivate static var subjectRegularFont: UIFont {
return WPStyleGuide.fontForTextStyle(.subheadline)
}
fileprivate static var subjectSemiBoldFont: UIFont {
return WPStyleGuide.fontForTextStyle(.subheadline, fontWeight: .semibold)
}
fileprivate static var subjectItalicsFont: UIFont {
return WPStyleGuide.fontForTextStyle(.subheadline, symbolicTraits: .traitItalic)
}
fileprivate static let subjectNoticonFont = UIFont(name: "Noticons", size: subjectNoticonSize)!
fileprivate static let headerTitleRegularFont = blockRegularFont
fileprivate static let headerTitleItalicsFont = blockItalicsFont
fileprivate static let blockItalicsFont = WPFontManager.systemItalicFont(ofSize: blockFontSize)
fileprivate static let blockNoticonFont = subjectNoticonFont
}
}
// FIXME: Duplicated move to appropriate location
extension UIFont {
/// Returns a UIFont instance with the italic trait applied.
func italic() -> UIFont {
return withSymbolicTraits(.traitItalic)
}
/// Returns a UIFont instance with the semibold trait applied.
func semibold() -> UIFont {
return withWeight(.semibold)
}
private func withSymbolicTraits(_ traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else {
return self
}
return UIFont(descriptor: descriptor, size: 0)
}
private func withWeight(_ weight: UIFont.Weight) -> UIFont {
let descriptor = fontDescriptor.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: weight]])
return UIFont(descriptor: descriptor, size: 0)
}
}