Skip to content

Commit 734161a

Browse files
authored
Move some content group and styles to FormattableContentKit (#24265)
* Move some content group and styles to FormattableContentKit These are needed by the WordPressData files. * Address SwiftLint violations * Change `formatter` to `private` * Add note to address #24297
1 parent 474abd4 commit 734161a

File tree

11 files changed

+86
-28
lines changed

11 files changed

+86
-28
lines changed

Modules/Package.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ let package = Package(
7777
resources: [.process("Resources")],
7878
swiftSettings: [.swiftLanguageMode(.v5)]
7979
),
80-
.target(name: "FormattableContentKit", dependencies: ["WordPressShared"]),
80+
.target(
81+
name: "FormattableContentKit",
82+
dependencies: [
83+
"WordPressShared",
84+
"WordPressUI",
85+
.product(name: "Gridicons", package: "Gridicons-iOS"),
86+
// TODO: Remove — It's here just for a NSMutableParagraphStyle init helper
87+
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
88+
],
89+
// Set to v5 to avoid @Sendable warnings and errors
90+
swiftSettings: [.swiftLanguageMode(.v5)]
91+
),
8192
.target(name: "JetpackStatsWidgetsCore", swiftSettings: [.swiftLanguageMode(.v5)]),
8293
.target(
8394
name: "ShareExtensionCore",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class HeaderContentGroup: FormattableContentGroup {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class SubjectContentGroup: FormattableContentGroup {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import WordPressShared
2+
3+
public class SnippetsContentStyles: FormattableContentStyles {
4+
public var attributes: [NSAttributedString.Key: Any] {
5+
return WPStyleGuide.Notifications.snippetRegularStyle
6+
}
7+
8+
public var quoteStyles: [NSAttributedString.Key: Any]?
9+
10+
public var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]?
11+
12+
public var linksColor: UIColor?
13+
14+
public var key: String
15+
16+
public init(
17+
quoteStyles: [NSAttributedString.Key: Any]? = nil,
18+
rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? = nil,
19+
linksColor: UIColor? = nil,
20+
key: String = "SnippetsContentStyles"
21+
) {
22+
self.quoteStyles = quoteStyles
23+
self.rangeStylesMap = rangeStylesMap
24+
self.linksColor = linksColor
25+
self.key = key
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import WordPressShared
2-
import FormattableContentKit
32

4-
class SubjectContentStyles: FormattableContentStyles {
5-
var attributes: [NSAttributedString.Key: Any] {
3+
public class SubjectContentStyles: FormattableContentStyles {
4+
public var attributes: [NSAttributedString.Key: Any] {
65
return WPStyleGuide.Notifications.subjectRegularStyle
76
}
87

9-
var quoteStyles: [NSAttributedString.Key: Any]? {
8+
public var quoteStyles: [NSAttributedString.Key: Any]? {
109
return WPStyleGuide.Notifications.subjectItalicsStyle
1110
}
1211

13-
var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? {
12+
public var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? {
1413
return [
1514
.user: WPStyleGuide.Notifications.subjectRegularStyle,
1615
.post: WPStyleGuide.Notifications.subjectRegularStyle,
@@ -21,6 +20,11 @@ class SubjectContentStyles: FormattableContentStyles {
2120
]
2221
}
2322

24-
var linksColor: UIColor? = nil
25-
var key: String = "SubjectContentStyles"
23+
public var linksColor: UIColor?
24+
public var key: String
25+
26+
public init(linkColor: UIColor? = nil, key: String = "SubjectContentStyles") {
27+
self.linksColor = linkColor
28+
self.key = key
29+
}
2630
}

WordPress/Classes/ViewRelated/Notifications/Style/WPStyleGuide+Notifications.swift renamed to Modules/Sources/FormattableContentKit/Styles/WPStyleGuide+Notifications.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// FIXME: This does not belong here, see https://github.com/wordpress-mobile/WordPress-iOS/pull/24297
12
import Foundation
2-
33
import Gridicons
4+
import UIKit
45
import WordPressShared
6+
import WordPressKit // FIXME: Here just for the NSMutableParagraphStyle custom init
57
import WordPressUI
68

79
extension WPStyleGuide {
@@ -285,3 +287,29 @@ extension WPStyleGuide {
285287
fileprivate static let blockNoticonFont = subjectNoticonFont
286288
}
287289
}
290+
291+
// FIXME: Duplicated move to appropriate location
292+
extension UIFont {
293+
/// Returns a UIFont instance with the italic trait applied.
294+
func italic() -> UIFont {
295+
return withSymbolicTraits(.traitItalic)
296+
}
297+
298+
/// Returns a UIFont instance with the semibold trait applied.
299+
func semibold() -> UIFont {
300+
return withWeight(.semibold)
301+
}
302+
303+
private func withSymbolicTraits(_ traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
304+
guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else {
305+
return self
306+
}
307+
308+
return UIFont(descriptor: descriptor, size: 0)
309+
}
310+
311+
private func withWeight(_ weight: UIFont.Weight) -> UIFont {
312+
let descriptor = fontDescriptor.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: weight]])
313+
return UIFont(descriptor: descriptor, size: 0)
314+
}
315+
}

WordPress/Classes/Models/Notifications/Notification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Notification: NSManagedObject {
6363
///
6464
fileprivate var cachedTimestampAsDate: Date?
6565

66-
let formatter = FormattableContentFormatter()
66+
private let formatter = FormattableContentFormatter()
6767

6868
/// Subject Blocks Transient Storage.
6969
///

WordPress/Classes/ViewRelated/Notifications/FormattableContent/Groups/HeaderContentGroup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import FormattableContentKit
22

3-
class HeaderContentGroup: FormattableContentGroup {
3+
extension HeaderContentGroup {
44
class func createGroup(from header: [[String: AnyObject]], parent: Notification) -> FormattableContentGroup {
55
let blocks = NotificationContentFactory.content(from: header, actionsParser: NotificationActionParser(), parent: parent)
66
return FormattableContentGroup(blocks: blocks, kind: .header)

WordPress/Classes/ViewRelated/Notifications/FormattableContent/Groups/SubjectContentGroup.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import FormattableContentKit
22

3-
class SubjectContentGroup: FormattableContentGroup {
3+
extension SubjectContentGroup {
4+
45
class func createGroup(from subject: [[String: AnyObject]], parent: Notification) -> FormattableContentGroup {
56
let blocks = NotificationContentFactory.content(from: subject, actionsParser: NotificationActionParser(), parent: parent)
67
return FormattableContentGroup(blocks: blocks, kind: .subject)

WordPress/Classes/ViewRelated/Notifications/FormattableContent/Styles/SnippetsContentStyles.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)