Skip to content

Commit 381c907

Browse files
authored
Notifications Refresh (Phase 1) (#22524)
2 parents 267faeb + f6202c5 commit 381c907

File tree

65 files changed

+2258
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2258
-366
lines changed

Modules/Package.swift

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ let package = Package(
2020
name: "\(jetpackStatsWidgetsCoreName)Tests",
2121
dependencies: [.target(name: jetpackStatsWidgetsCoreName)]
2222
),
23+
.testTarget(
24+
name: "\(designSystemName)Tests",
25+
dependencies: [.target(name: designSystemName)]
26+
),
2327
.target(name: designSystemName)
2428
]
2529
)
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,11 @@
11
import SwiftUI
22

3-
// MARK: - SwiftUI.Font: TextStyle
4-
extension TextStyle {
5-
var font: Font {
6-
switch self {
7-
case .heading1:
8-
return Font.DS.heading1
9-
10-
case .heading2:
11-
return Font.DS.heading2
12-
13-
case .heading3:
14-
return Font.DS.heading3
15-
16-
case .heading4:
17-
return Font.DS.heading4
18-
19-
case .bodySmall(let weight):
20-
switch weight {
21-
case .regular:
22-
return Font.DS.Body.small
23-
case .emphasized:
24-
return Font.DS.Body.Emphasized.small
25-
}
26-
27-
case .bodyMedium(let weight):
28-
switch weight {
29-
case .regular:
30-
return Font.DS.Body.medium
31-
case .emphasized:
32-
return Font.DS.Body.Emphasized.medium
33-
}
34-
35-
case .bodyLarge(let weight):
36-
switch weight {
37-
case .regular:
38-
return Font.DS.Body.large
39-
case .emphasized:
40-
return Font.DS.Body.Emphasized.large
41-
}
42-
43-
case .footnote:
44-
return Font.DS.footnote
45-
46-
case .caption:
47-
return Font.DS.caption
48-
}
49-
}
50-
51-
var `case`: Text.Case? {
52-
switch self {
53-
case .caption:
54-
return .uppercase
55-
default:
56-
return nil
57-
}
58-
}
59-
}
60-
613
// MARK: - SwiftUI.Text
624
public extension Text {
635
@ViewBuilder
646
func style(_ style: TextStyle) -> some View {
65-
self.font(style.font)
7+
let font = Font.DS.font(style)
8+
self.font(font)
669
.textCase(style.case)
6710
}
6811
}
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,11 @@
11
import UIKit
22

3-
// MARK: - UIKit.UIFont: TextStyle
4-
public extension TextStyle {
5-
var uiFont: UIFont {
6-
switch self {
7-
case .heading1:
8-
return UIFont.DS.heading1
9-
10-
case .heading2:
11-
return UIFont.DS.heading2
12-
13-
case .heading3:
14-
return UIFont.DS.heading3
15-
16-
case .heading4:
17-
return UIFont.DS.heading4
18-
19-
case .bodySmall(let weight):
20-
switch weight {
21-
case .regular:
22-
return UIFont.DS.Body.small
23-
case .emphasized:
24-
return UIFont.DS.Body.Emphasized.small
25-
}
26-
27-
case .bodyMedium(let weight):
28-
switch weight {
29-
case .regular:
30-
return UIFont.DS.Body.medium
31-
case .emphasized:
32-
return UIFont.DS.Body.Emphasized.medium
33-
}
34-
35-
case .bodyLarge(let weight):
36-
switch weight {
37-
case .regular:
38-
return UIFont.DS.Body.large
39-
case .emphasized:
40-
return UIFont.DS.Body.Emphasized.large
41-
}
42-
43-
case .footnote:
44-
return UIFont.DS.footnote
45-
46-
case .caption:
47-
return UIFont.DS.caption
48-
}
49-
}
50-
}
51-
52-
// MARK: - SwiftUI.Text
53-
public extension UILabel {
54-
func setStyle(_ style: TextStyle) {
55-
self.font = style.uiFont
3+
extension UILabel {
4+
func style(_ style: TextStyle) -> Self {
5+
self.font = UIFont.DS.font(style)
566
if style.case == .uppercase {
577
self.text = self.text?.uppercased()
588
}
59-
}
60-
}
61-
62-
// MARK: - UIKit.UIFont
63-
fileprivate extension UIFont {
64-
enum DS {
65-
static let heading1 = DynamicFontHelper.fontForTextStyle(.largeTitle, fontWeight: .bold)
66-
static let heading2 = DynamicFontHelper.fontForTextStyle(.title1, fontWeight: .bold)
67-
static let heading3 = DynamicFontHelper.fontForTextStyle(.title2, fontWeight: .bold)
68-
static let heading4 = DynamicFontHelper.fontForTextStyle(.title3, fontWeight: .semibold)
69-
70-
enum Body {
71-
static let small = DynamicFontHelper.fontForTextStyle(.subheadline, fontWeight: .regular)
72-
static let medium = DynamicFontHelper.fontForTextStyle(.callout, fontWeight: .regular)
73-
static let large = DynamicFontHelper.fontForTextStyle(.body, fontWeight: .regular)
74-
75-
enum Emphasized {
76-
static let small = DynamicFontHelper.fontForTextStyle(.subheadline, fontWeight: .semibold)
77-
static let medium = DynamicFontHelper.fontForTextStyle(.callout, fontWeight: .semibold)
78-
static let large = DynamicFontHelper.fontForTextStyle(.body, fontWeight: .semibold)
79-
}
80-
}
81-
82-
static let footnote = DynamicFontHelper.fontForTextStyle(.footnote, fontWeight: .regular)
83-
static let caption = DynamicFontHelper.fontForTextStyle(.caption1, fontWeight: .regular)
84-
}
85-
}
86-
87-
private enum DynamicFontHelper {
88-
static func fontForTextStyle(_ style: UIFont.TextStyle, fontWeight weight: UIFont.Weight) -> UIFont {
89-
/// WORKAROUND: Some font weights scale up well initially but they don't scale up well if dynamic type
90-
/// is changed in real time. Creating a scaled font offers an alternative solution that works well
91-
/// even in real time.
92-
let weightsThatNeedScaledFont: [UIFont.Weight] = [.black, .bold, .heavy, .semibold]
93-
94-
guard !weightsThatNeedScaledFont.contains(weight) else {
95-
return scaledFont(for: style, weight: weight)
96-
}
97-
98-
var fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
99-
100-
let traits = [UIFontDescriptor.TraitKey.weight: weight]
101-
fontDescriptor = fontDescriptor.addingAttributes([.traits: traits])
102-
103-
return UIFont(descriptor: fontDescriptor, size: CGFloat(0.0))
104-
}
105-
106-
static func scaledFont(for style: UIFont.TextStyle, weight: UIFont.Weight, design: UIFontDescriptor.SystemDesign = .default) -> UIFont {
107-
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
108-
let fontDescriptorWithDesign = fontDescriptor.withDesign(design) ?? fontDescriptor
109-
let traits = [UIFontDescriptor.TraitKey.weight: weight]
110-
let finalDescriptor = fontDescriptorWithDesign.addingAttributes([.traits: traits])
111-
112-
return UIFont(descriptor: finalDescriptor, size: finalDescriptor.pointSize)
9+
return self
11310
}
11411
}

Modules/Sources/DesignSystem/Foundation/Font+DesignSystem.swift

+48
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,51 @@ public extension Font {
2323
public static let caption = Font.caption
2424
}
2525
}
26+
27+
public extension Font.DS {
28+
static func font(_ style: DesignSystem.TextStyle) -> Font {
29+
switch style {
30+
case .heading1:
31+
return Font.DS.heading1
32+
33+
case .heading2:
34+
return Font.DS.heading2
35+
36+
case .heading3:
37+
return Font.DS.heading3
38+
39+
case .heading4:
40+
return Font.DS.heading4
41+
42+
case .bodySmall(let weight):
43+
switch weight {
44+
case .regular:
45+
return Font.DS.Body.small
46+
case .emphasized:
47+
return Font.DS.Body.Emphasized.small
48+
}
49+
50+
case .bodyMedium(let weight):
51+
switch weight {
52+
case .regular:
53+
return Font.DS.Body.medium
54+
case .emphasized:
55+
return Font.DS.Body.Emphasized.medium
56+
}
57+
58+
case .bodyLarge(let weight):
59+
switch weight {
60+
case .regular:
61+
return Font.DS.Body.large
62+
case .emphasized:
63+
return Font.DS.Body.Emphasized.large
64+
}
65+
66+
case .footnote:
67+
return Font.DS.footnote
68+
69+
case .caption:
70+
return Font.DS.caption
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import UIKit
2+
import SwiftUI
3+
4+
/// `Icon` provides a namespace for icon identifiers.
5+
///
6+
/// The naming convention follows the SF Symbols guidelines, enhancing consistency and readability.
7+
/// Each icon name is a dot-syntax representation of the icon's hierarchy and style.
8+
///
9+
/// For example, `ellipsis.vertical` represents a vertical ellipsis icon.
10+
public enum IconName: String, CaseIterable {
11+
case ellipsisHorizontal = "ellipsis.horizontal"
12+
case checkmark
13+
case gearshapeFill = "gearshape.fill"
14+
case blockShare = "block.share"
15+
case starFill = "star.fill"
16+
case starOutline = "star.outline"
17+
}
18+
19+
// MARK: - Load Image
20+
21+
public extension UIImage {
22+
enum DS {
23+
public static func icon(named name: IconName, with configuration: UIImage.Configuration? = nil) -> UIImage? {
24+
return UIImage(named: name.rawValue, in: .module, with: configuration)
25+
}
26+
}
27+
}
28+
29+
public extension Image {
30+
enum DS {
31+
public static func icon(named name: IconName) -> Image {
32+
return Image(name.rawValue, bundle: .module)
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "block-share.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "checkmark.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "more-horizontal-mobile.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "cog.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "star-fill.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true,
14+
"template-rendering-intent" : "template"
15+
}
16+
}

0 commit comments

Comments
 (0)