Skip to content
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

Move some content group and styles to FormattableContentKit #24265

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
@@ -72,7 +72,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 +79 to +82
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",
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,
@@ -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,8 @@
import Foundation

import Gridicons
import UIKit
import WordPressShared
import WordPressKit // FIXME: Here just for the NSMutableParagraphStyle custom init
import WordPressUI

extension WPStyleGuide {
@@ -285,3 +286,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)
}
}
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)
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)

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 {