Skip to content

Commit 169c4f4

Browse files
PanchamiShenoyPanchamiShenoy
authored andcommitted
[CM - 913] Added lineHeight mutator method
1 parent 8aba042 commit 169c4f4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Sources/YMatterType/Typography/Typography+Mutators.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ public extension Typography {
6060
isFixed: isFixed
6161
)
6262
}
63+
64+
/// Returns a copy of the Typography but with the new `lineHeight` applied.
65+
/// - Parameter value: the line height to use
66+
/// - Returns: an updated copy of the Typography
67+
func lineHeight(_ value: CGFloat) -> Typography {
68+
if lineHeight == value { return self }
69+
70+
return Typography(
71+
fontFamily: fontFamily,
72+
fontWeight: fontWeight,
73+
fontSize: fontSize,
74+
lineHeight: value,
75+
letterSpacing: letterSpacing,
76+
paragraphIndent: paragraphIndent,
77+
paragraphSpacing: paragraphSpacing,
78+
textCase: textCase,
79+
textDecoration: textDecoration,
80+
textStyle: textStyle,
81+
isFixed: isFixed
82+
)
83+
}
6384

6485
/// Returns a copy of the Typography but with `isFixed` set to `true`
6586
var fixed: Typography {

Tests/YMatterTypeTests/Typography/Typography+MutatorsTests.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ final class TypographyMutatorsTests: XCTestCase {
5353
_test(original: $0, modified: $0.fontSize(newFontSize), fontSize: newFontSize)
5454
}
5555
}
56+
57+
func testLineHeight() {
58+
types.forEach {
59+
_test(original: $0, modified: $0.lineHeight($0.lineHeight + 1), lineHeight: ($0.lineHeight + 1))
60+
}
61+
}
5662

5763
func testFixed() {
5864
types.forEach {
@@ -89,13 +95,15 @@ final class TypographyMutatorsTests: XCTestCase {
8995
modified: Typography,
9096
weight: Typography.FontWeight? = nil,
9197
fontSize: CGFloat? = nil,
98+
lineHeight: CGFloat? = nil,
9299
isFixed: Bool? = nil,
93100
letterSpacing: CGFloat? = nil,
94101
textCase: Typography.TextCase? = nil,
95102
textDecoration: Typography.TextDecoration? = nil
96103
) {
97104
let weight = weight ?? original.fontWeight
98105
let fontSize = fontSize ?? original.fontSize
106+
let lineHeight = lineHeight ?? original.lineHeight
99107
let isFixed = isFixed ?? original.isFixed
100108
let kerning = letterSpacing ?? original.letterSpacing
101109
let textCase = textCase ?? original.textCase
@@ -104,14 +112,14 @@ final class TypographyMutatorsTests: XCTestCase {
104112
// fontWeight, fontSize, isFixed, letterSpacing, textCase, and textDecoration should be as expected
105113
XCTAssertEqual(modified.fontWeight, weight)
106114
XCTAssertEqual(modified.fontSize, fontSize)
115+
XCTAssertEqual(modified.lineHeight, lineHeight)
107116
XCTAssertEqual(modified.isFixed, isFixed)
108117
XCTAssertEqual(modified.letterSpacing, kerning)
109118
XCTAssertEqual(modified.textCase, textCase)
110119
XCTAssertEqual(modified.textDecoration, textDecoration)
111120

112121
// the other variables should be the same
113122
XCTAssertEqual(modified.fontFamily.familyName, original.fontFamily.familyName)
114-
XCTAssertEqual(modified.lineHeight, original.lineHeight)
115123
XCTAssertEqual(modified.textStyle, original.textStyle)
116124
XCTAssertEqual(modified.paragraphIndent, original.paragraphIndent)
117125
XCTAssertEqual(modified.paragraphSpacing, original.paragraphSpacing)

0 commit comments

Comments
 (0)