Skip to content

Commit 85bbd08

Browse files
committed
[UPDATE] review comments resolved
1 parent 88122bf commit 85bbd08

File tree

10 files changed

+45
-46
lines changed

10 files changed

+45
-46
lines changed

Sources/YCoreUI/Extensions/UIKit/UIColor+rgbComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
// This relatively simple tuple (four float values representing the color channels)
1212
// is already a released public api.
13-
// swiftlint:disable superfluous_disable_command large_tuple
13+
// swiftlint: disable large_tuple
1414

1515
/// Tuple representing Red, Green, Blue, and Alpha color channel components
1616
public typealias RGBAComponents = (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
@@ -29,4 +29,4 @@ public extension UIColor {
2929
return (red, green, blue, alpha)
3030
}
3131
}
32-
// swiftlint: enable superfluous_disable_command large_tuple
32+
// swiftlint: enable large_tuple

Sources/YCoreUI/Protocols/ImageAsset.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
2020

2121
/// Optional namespace for the image assets (default is `nil`).
2222
static var namespace: String? { get }
23-
24-
/// Optional renderingMode to use for the image (default is `nil`)
25-
static var renderingMode: UIImage.RenderingMode? { get }
26-
23+
2724
/// Fallback image to use in case an image asset cannot be loaded.
2825
/// (default is a 16 x 16 square filled with `.systemPink`)
2926
static var fallbackImage: UIImage { get }
@@ -42,10 +39,7 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
4239
extension ImageAsset {
4340
/// The bundle containing the image assets for this enum (default is `.main`)
4441
public static var bundle: Bundle { .main }
45-
46-
/// Optional renderingMode to use for the image (default is `nil`)
47-
public static var renderingMode: UIImage.RenderingMode? { nil }
48-
42+
4943
/// Optional namespace for the image assets (default is `nil`)
5044
public static var namespace: String? { nil }
5145

@@ -66,11 +60,7 @@ extension ImageAsset {
6660
/// (prepended to `rawValue`) and `bundle`.
6761
/// - Returns: The named image or else `nil` if the named asset cannot be loaded.
6862
public func loadImage() -> UIImage? {
69-
let image = UIImage(named: calculateName(), in: Self.bundle, compatibleWith: nil)
70-
guard let renderingMode = Self.renderingMode else {
71-
return image
72-
}
73-
return image?.withRenderingMode(renderingMode)
63+
UIImage(named: calculateName(), in: Self.bundle, compatibleWith: nil)
7464
}
7565

7666
internal func calculateName() -> String {

Sources/YCoreUI/Protocols/SystemImage.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public protocol SystemImage: RawRepresentable where RawValue == String {
1717
/// (default is a 16 x 16 square filled with `.systemPink`)
1818
static var fallbackImage: UIImage { get }
1919

20+
/// Optional rendering mode to use for the image (default is `nil`)
21+
static var renderingMode: UIImage.RenderingMode? { get }
22+
2023
/// A system image for this name value.
2124
///
2225
/// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
@@ -41,7 +44,10 @@ public protocol SystemImage: RawRepresentable where RawValue == String {
4144
extension SystemImage {
4245
/// Image will scale according to the specified text style.
4346
public static var textStyle: UIFont.TextStyle? { .body }
44-
47+
48+
/// Optional rendering mode to use for the image (default is `nil`)
49+
public static var renderingMode: UIImage.RenderingMode? { nil }
50+
4551
/// Image configuration to be used in `loadImage()`.
4652
///
4753
/// Returns `nil` when `textStyle` is `nil`.
@@ -68,7 +74,11 @@ extension SystemImage {
6874
/// Default implementation uses `UIImage(systemName:)` passing in the associated `rawValue`.
6975
/// - Returns: The named system image or else `nil` if the system image cannot be loaded.
7076
public func loadImage() -> UIImage? {
71-
UIImage(systemName: rawValue, withConfiguration: Self.configuration)
77+
let image = UIImage(systemName: rawValue, withConfiguration: Self.configuration)
78+
guard let renderingMode = Self.renderingMode else {
79+
return image
80+
}
81+
return image?.withRenderingMode(renderingMode)
7282
}
7383

7484
/// A system image for this name value.

Tests/YCoreUITests/Extensions/Foundation/CGFloat+roundedTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import XCTest
1010
@testable import YCoreUI
1111

1212
// Large tuples help us build unit test expectations concisely
13-
// swiftlint:disable superfluous_disable_command large_tuple
13+
// swiftlint: disable large_tuple
1414

1515
final class CGFloatRoundedTests: XCTestCase {
1616
typealias ScalingInputs = (
@@ -75,4 +75,4 @@ final class CGFloatRoundedTests: XCTestCase {
7575
}
7676
}
7777
}
78-
// swiftlint: enable large_tuple superfluous_disable_command
78+
// swiftlint: enable large_tuple

Tests/YCoreUITests/Extensions/UIKit/UIColor+WCAGTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import XCTest
1010
@testable import YCoreUI
1111

1212
// Large tuples help us build unit test expectations concisely
13-
// swiftlint:disable superfluous_disable_command large_tuple
13+
// swiftlint: disable large_tuple
1414

1515
final class UIColorWCAGTests: XCTestCase {
1616
typealias ColorInputs = (foreground: UIColor, background: UIColor, context: WCAGContext)
@@ -183,4 +183,4 @@ final class UIColorWCAGTests: XCTestCase {
183183
XCTAssertEqual(round(ratio1 * 100) / 100, round(ratio2 * 100) / 100)
184184
}
185185
}
186-
// swiftlint: enable large_tuple superfluous_disable_command
186+
// swiftlint: enable large_tuple

Tests/YCoreUITests/Extensions/UIKit/UIColor+rgbValueTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import XCTest
1010
@testable import YCoreUI
1111

1212
// Large tuples help us build unit test expectations concisely
13-
// swiftlint:disable superfluous_disable_command large_tuple
13+
// swiftlint: disable large_tuple
1414

1515
final class UIColorRgbValueTests: XCTestCase {
1616
typealias ColorTest = (color: UIColor, prefix: String?, isUppercase: Bool, output: String)
@@ -75,4 +75,4 @@ final class UIColorRgbValueTests: XCTestCase {
7575
YCoreUI.isLoggingEnabled = true
7676
}
7777
}
78-
// swiftlint: enable large_tuple superfluous_disable_command
78+
// swiftlint: enable large_tuple

Tests/YCoreUITests/Extensions/UIKit/UIView+constrainAnchorTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import XCTest
1010
@testable import YCoreUI
1111

12-
// swiftlint:disable superfluous_disable_command type_body_length
13-
1412
final class UIViewConstrainAnchorTests: XCTestCase {
1513
func testXAxisConstraints() {
1614
let (sut, relations) = makeSUT()
@@ -380,4 +378,3 @@ private extension MockLayoutContainer {
380378
addSubview(view2)
381379
}
382380
}
383-
// swiftlint:enable superfluous_disable_command type_body_length

Tests/YCoreUITests/Extensions/UIKit/UIView+constrainEdgesTests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import XCTest
1010

11-
// swiftlint:disable superfluous_disable_command
1211
final class UIViewConstrainEdgesTests: XCTestCase {
1312
func testSimple() {
1413
let (sut, insets) = makeSUT()
@@ -51,7 +50,6 @@ final class UIViewConstrainEdgesTests: XCTestCase {
5150
XCTAssertEqual(trailing?.secondAttribute, .trailing)
5251
XCTAssertEqual(trailing?.constant, -insets.trailing)
5352
}
54-
// swiftlint:disable function_body_length
5553
func testPartialEdges() {
5654
let (sut, _) = makeSUT()
5755
let edges: [NSDirectionalRectEdge] = [
@@ -115,8 +113,7 @@ final class UIViewConstrainEdgesTests: XCTestCase {
115113
button.removeFromSuperview()
116114
}
117115
}
118-
// swiftlint:enable function_body_length
119-
116+
120117
func testRelation() {
121118
let (sut, _) = makeSUT()
122119
let relations: [(input: NSLayoutConstraint.Relation, inverse: NSLayoutConstraint.Relation)] = [
@@ -178,4 +175,3 @@ private extension UIViewConstrainEdgesTests {
178175
return (container, insets)
179176
}
180177
}
181-
// swiftlint: enable superfluous_disable_command

Tests/YCoreUITests/Protocols/ImageAssetTests.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ final class ImageAssetTests: XCTestCase {
4040
XCTAssertNotEqual($0.image.pngData(), DefaultImageAssets.fallbackImage.pngData())
4141
}
4242
}
43-
44-
func test_loadImageWithRenderingMode() {
45-
RenderMode.allCases.forEach {
46-
XCTAssertNotNil($0.loadImage())
47-
}
48-
}
4943

5044
func test_missingImage() {
5145
YCoreUI.isLoggingEnabled = false
@@ -106,13 +100,4 @@ extension ImageAssetTests {
106100
return image
107101
}
108102
}
109-
110-
enum RenderMode: String, CaseIterable, ImageAsset {
111-
case unitedStates = "flag_us"
112-
case india = "flag_in"
113-
case switzerland = "flag_ch"
114-
115-
static var bundle: Bundle { .module }
116-
static var renderingMode: UIImage.RenderingMode? { .alwaysOriginal }
117-
}
118103
}

Tests/YCoreUITests/Protocols/SystemImageTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ final class SystemImageTests: XCTestCase {
3333
YCoreUI.isLoggingEnabled = true
3434
}
3535

36+
func test_loadImageWithRenderingMode() {
37+
RenderMode.allCases.forEach {
38+
XCTAssertEqual(
39+
$0.loadImage()?.pngData(),
40+
UIImage(
41+
systemName: $0.rawValue,
42+
withConfiguration: RenderMode.configuration
43+
)?.withRenderingMode(RenderMode.renderingMode ?? .alwaysTemplate).pngData()
44+
)
45+
XCTAssertEqual($0.image.renderingMode, .alwaysOriginal)
46+
}
47+
}
48+
3649
func test_defaultImageScaling() {
3750
XCTAssertEqual(Symbols.textStyle, .body)
3851
XCTAssertEqual(Symbols.configuration, UIImage.SymbolConfiguration(textStyle: .body))
@@ -88,4 +101,12 @@ extension SystemImageTests {
88101

89102
static var textStyle: UIFont.TextStyle? { .title1 }
90103
}
104+
105+
enum RenderMode: String, CaseIterable, SystemImage {
106+
case plus
107+
case minus
108+
case trash
109+
110+
static var renderingMode: UIImage.RenderingMode? { .alwaysOriginal }
111+
}
91112
}

0 commit comments

Comments
 (0)