Skip to content

Move some content group and styles to FormattableContentKit #24265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ let package = Package(
resources: [.process("Resources")],
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(name: "FormattableContentKit", dependencies: ["WordPressShared"]),
.target(
name: "FormattableContentKit",
dependencies: [
"WordPressShared",
"WordPressUI",
.product(name: "Gridicons", package: "Gridicons-iOS"),
// TODO: Remove — It's here just for a NSMutableParagraphStyle init helper
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
Comment on lines +84 to +87
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
// Set to v5 to avoid @Sendable warnings and errors
swiftSettings: [.swiftLanguageMode(.v5)]
),
.target(name: "JetpackStatsWidgetsCore", swiftSettings: [.swiftLanguageMode(.v5)]),
.target(
name: "ShareExtensionCore",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class HeaderContentGroup: FormattableContentGroup {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class SubjectContentGroup: FormattableContentGroup {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import WordPressShared

public class SnippetsContentStyles: FormattableContentStyles {
public var attributes: [NSAttributedString.Key: Any] {
return WPStyleGuide.Notifications.snippetRegularStyle
}

public var quoteStyles: [NSAttributedString.Key: Any]?

public var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]?

public var linksColor: UIColor?

public var key: String

public init(
quoteStyles: [NSAttributedString.Key: Any]? = nil,
rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? = nil,
linksColor: UIColor? = nil,
key: String = "SnippetsContentStyles"
) {
self.quoteStyles = quoteStyles
self.rangeStylesMap = rangeStylesMap
self.linksColor = linksColor
self.key = key
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import WordPressShared
import FormattableContentKit

class SubjectContentStyles: FormattableContentStyles {
var attributes: [NSAttributedString.Key: Any] {
public class SubjectContentStyles: FormattableContentStyles {
public var attributes: [NSAttributedString.Key: Any] {
return WPStyleGuide.Notifications.subjectRegularStyle
}

var quoteStyles: [NSAttributedString.Key: Any]? {
public var quoteStyles: [NSAttributedString.Key: Any]? {
return WPStyleGuide.Notifications.subjectItalicsStyle
}

var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? {
public var rangeStylesMap: [FormattableRangeKind: [NSAttributedString.Key: Any]]? {
return [
.user: WPStyleGuide.Notifications.subjectRegularStyle,
.post: WPStyleGuide.Notifications.subjectRegularStyle,
Expand All @@ -21,6 +20,11 @@ class SubjectContentStyles: FormattableContentStyles {
]
}

var linksColor: UIColor? = nil
var key: String = "SubjectContentStyles"
public var linksColor: UIColor?
public var key: String

public init(linkColor: UIColor? = nil, key: String = "SubjectContentStyles") {
self.linksColor = linkColor
self.key = key
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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 WordPressKit // FIXME: Here just for the NSMutableParagraphStyle custom init
import WordPressUI

extension WPStyleGuide {
Expand Down Expand Up @@ -285,3 +287,29 @@ extension WPStyleGuide {
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)
}
}
2 changes: 1 addition & 1 deletion WordPress/Classes/Models/Notifications/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Notification: NSManagedObject {
///
fileprivate var cachedTimestampAsDate: Date?

let formatter = FormattableContentFormatter()
private let formatter = FormattableContentFormatter()

/// Subject Blocks Transient Storage.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FormattableContentKit

class HeaderContentGroup: FormattableContentGroup {
extension HeaderContentGroup {
class func createGroup(from header: [[String: AnyObject]], parent: Notification) -> FormattableContentGroup {
let blocks = NotificationContentFactory.content(from: header, actionsParser: NotificationActionParser(), parent: parent)
return FormattableContentGroup(blocks: blocks, kind: .header)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FormattableContentKit

class SubjectContentGroup: FormattableContentGroup {
extension SubjectContentGroup {

class func createGroup(from subject: [[String: AnyObject]], parent: Notification) -> FormattableContentGroup {
let blocks = NotificationContentFactory.content(from: subject, actionsParser: NotificationActionParser(), parent: parent)
return FormattableContentGroup(blocks: blocks, kind: .subject)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import FormattableContentKit

class LikeUserTableViewCell: UITableViewCell, NibReusable {

Expand Down