Skip to content

Commit

Permalink
Notifications Refresh (Phase 1) (#22524)
Browse files Browse the repository at this point in the history
  • Loading branch information
alpavanoglu committed Feb 28, 2024
2 parents 267faeb + f6202c5 commit 381c907
Show file tree
Hide file tree
Showing 65 changed files with 2,258 additions and 366 deletions.
4 changes: 4 additions & 0 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ let package = Package(
name: "\(jetpackStatsWidgetsCoreName)Tests",
dependencies: [.target(name: jetpackStatsWidgetsCoreName)]
),
.testTarget(
name: "\(designSystemName)Tests",
dependencies: [.target(name: designSystemName)]
),
.target(name: designSystemName)
]
)
Original file line number Diff line number Diff line change
@@ -1,68 +1,11 @@
import SwiftUI

// MARK: - SwiftUI.Font: TextStyle
extension TextStyle {
var font: Font {
switch self {
case .heading1:
return Font.DS.heading1

case .heading2:
return Font.DS.heading2

case .heading3:
return Font.DS.heading3

case .heading4:
return Font.DS.heading4

case .bodySmall(let weight):
switch weight {
case .regular:
return Font.DS.Body.small
case .emphasized:
return Font.DS.Body.Emphasized.small
}

case .bodyMedium(let weight):
switch weight {
case .regular:
return Font.DS.Body.medium
case .emphasized:
return Font.DS.Body.Emphasized.medium
}

case .bodyLarge(let weight):
switch weight {
case .regular:
return Font.DS.Body.large
case .emphasized:
return Font.DS.Body.Emphasized.large
}

case .footnote:
return Font.DS.footnote

case .caption:
return Font.DS.caption
}
}

var `case`: Text.Case? {
switch self {
case .caption:
return .uppercase
default:
return nil
}
}
}

// MARK: - SwiftUI.Text
public extension Text {
@ViewBuilder
func style(_ style: TextStyle) -> some View {
self.font(style.font)
let font = Font.DS.font(style)
self.font(font)
.textCase(style.case)
}
}
Original file line number Diff line number Diff line change
@@ -1,114 +1,11 @@
import UIKit

// MARK: - UIKit.UIFont: TextStyle
public extension TextStyle {
var uiFont: UIFont {
switch self {
case .heading1:
return UIFont.DS.heading1

case .heading2:
return UIFont.DS.heading2

case .heading3:
return UIFont.DS.heading3

case .heading4:
return UIFont.DS.heading4

case .bodySmall(let weight):
switch weight {
case .regular:
return UIFont.DS.Body.small
case .emphasized:
return UIFont.DS.Body.Emphasized.small
}

case .bodyMedium(let weight):
switch weight {
case .regular:
return UIFont.DS.Body.medium
case .emphasized:
return UIFont.DS.Body.Emphasized.medium
}

case .bodyLarge(let weight):
switch weight {
case .regular:
return UIFont.DS.Body.large
case .emphasized:
return UIFont.DS.Body.Emphasized.large
}

case .footnote:
return UIFont.DS.footnote

case .caption:
return UIFont.DS.caption
}
}
}

// MARK: - SwiftUI.Text
public extension UILabel {
func setStyle(_ style: TextStyle) {
self.font = style.uiFont
extension UILabel {
func style(_ style: TextStyle) -> Self {
self.font = UIFont.DS.font(style)
if style.case == .uppercase {
self.text = self.text?.uppercased()
}
}
}

// MARK: - UIKit.UIFont
fileprivate extension UIFont {
enum DS {
static let heading1 = DynamicFontHelper.fontForTextStyle(.largeTitle, fontWeight: .bold)
static let heading2 = DynamicFontHelper.fontForTextStyle(.title1, fontWeight: .bold)
static let heading3 = DynamicFontHelper.fontForTextStyle(.title2, fontWeight: .bold)
static let heading4 = DynamicFontHelper.fontForTextStyle(.title3, fontWeight: .semibold)

enum Body {
static let small = DynamicFontHelper.fontForTextStyle(.subheadline, fontWeight: .regular)
static let medium = DynamicFontHelper.fontForTextStyle(.callout, fontWeight: .regular)
static let large = DynamicFontHelper.fontForTextStyle(.body, fontWeight: .regular)

enum Emphasized {
static let small = DynamicFontHelper.fontForTextStyle(.subheadline, fontWeight: .semibold)
static let medium = DynamicFontHelper.fontForTextStyle(.callout, fontWeight: .semibold)
static let large = DynamicFontHelper.fontForTextStyle(.body, fontWeight: .semibold)
}
}

static let footnote = DynamicFontHelper.fontForTextStyle(.footnote, fontWeight: .regular)
static let caption = DynamicFontHelper.fontForTextStyle(.caption1, fontWeight: .regular)
}
}

private enum DynamicFontHelper {
static func fontForTextStyle(_ style: UIFont.TextStyle, fontWeight weight: UIFont.Weight) -> UIFont {
/// WORKAROUND: Some font weights scale up well initially but they don't scale up well if dynamic type
/// is changed in real time. Creating a scaled font offers an alternative solution that works well
/// even in real time.
let weightsThatNeedScaledFont: [UIFont.Weight] = [.black, .bold, .heavy, .semibold]

guard !weightsThatNeedScaledFont.contains(weight) else {
return scaledFont(for: style, weight: weight)
}

var fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)

let traits = [UIFontDescriptor.TraitKey.weight: weight]
fontDescriptor = fontDescriptor.addingAttributes([.traits: traits])

return UIFont(descriptor: fontDescriptor, size: CGFloat(0.0))
}

static func scaledFont(for style: UIFont.TextStyle, weight: UIFont.Weight, design: UIFontDescriptor.SystemDesign = .default) -> UIFont {
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
let fontDescriptorWithDesign = fontDescriptor.withDesign(design) ?? fontDescriptor
let traits = [UIFontDescriptor.TraitKey.weight: weight]
let finalDescriptor = fontDescriptorWithDesign.addingAttributes([.traits: traits])

return UIFont(descriptor: finalDescriptor, size: finalDescriptor.pointSize)
return self
}
}
48 changes: 48 additions & 0 deletions Modules/Sources/DesignSystem/Foundation/Font+DesignSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,51 @@ public extension Font {
public static let caption = Font.caption
}
}

public extension Font.DS {
static func font(_ style: DesignSystem.TextStyle) -> Font {
switch style {
case .heading1:
return Font.DS.heading1

case .heading2:
return Font.DS.heading2

case .heading3:
return Font.DS.heading3

case .heading4:
return Font.DS.heading4

case .bodySmall(let weight):
switch weight {
case .regular:
return Font.DS.Body.small
case .emphasized:
return Font.DS.Body.Emphasized.small
}

case .bodyMedium(let weight):
switch weight {
case .regular:
return Font.DS.Body.medium
case .emphasized:
return Font.DS.Body.Emphasized.medium
}

case .bodyLarge(let weight):
switch weight {
case .regular:
return Font.DS.Body.large
case .emphasized:
return Font.DS.Body.Emphasized.large
}

case .footnote:
return Font.DS.footnote

case .caption:
return Font.DS.caption
}
}
}
35 changes: 35 additions & 0 deletions Modules/Sources/DesignSystem/Foundation/IconName.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import UIKit
import SwiftUI

/// `Icon` provides a namespace for icon identifiers.
///
/// The naming convention follows the SF Symbols guidelines, enhancing consistency and readability.
/// Each icon name is a dot-syntax representation of the icon's hierarchy and style.
///
/// For example, `ellipsis.vertical` represents a vertical ellipsis icon.
public enum IconName: String, CaseIterable {
case ellipsisHorizontal = "ellipsis.horizontal"
case checkmark
case gearshapeFill = "gearshape.fill"
case blockShare = "block.share"
case starFill = "star.fill"
case starOutline = "star.outline"
}

// MARK: - Load Image

public extension UIImage {
enum DS {
public static func icon(named name: IconName, with configuration: UIImage.Configuration? = nil) -> UIImage? {
return UIImage(named: name.rawValue, in: .module, with: configuration)
}
}
}

public extension Image {
enum DS {
public static func icon(named name: IconName) -> Image {
return Image(name.rawValue, bundle: .module)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "block-share.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "checkmark.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "more-horizontal-mobile.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "cog.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "star-fill.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Loading

0 comments on commit 381c907

Please sign in to comment.