diff --git a/Sources/GravatarUI/DesignSystem/Palette.swift b/Sources/GravatarUI/DesignSystem/Palette.swift index df333766..66f88347 100644 --- a/Sources/GravatarUI/DesignSystem/Palette.swift +++ b/Sources/GravatarUI/DesignSystem/Palette.swift @@ -49,7 +49,7 @@ public struct Palette { /// - placeholder: Colors to use as placeholders. /// - preferredUserInterfaceStyle: Defines if this palette is a dark or light palette. /// This helps choose the correct images for this palette. Pass `.unspecified` to choose the system's user interface style. Default is `.unspecified`. - init( + public init( name: String, foreground: ForegroundColors, background: BackgroundColors, diff --git a/Sources/GravatarUI/ProfileView/Avatar/DefaultAvatarProvider.swift b/Sources/GravatarUI/ProfileView/Avatar/DefaultAvatarProvider.swift index cce6b356..189b17b2 100644 --- a/Sources/GravatarUI/ProfileView/Avatar/DefaultAvatarProvider.swift +++ b/Sources/GravatarUI/ProfileView/Avatar/DefaultAvatarProvider.swift @@ -47,6 +47,11 @@ class DefaultAvatarProvider: AvatarProviding { } } + private func applyAvatarActivityIndicatorTintColor() { + guard !skipStyling else { return } + avatarImageView.gravatar.activityIndicator?.view.tintColor = paletteType.palette.foreground.secondary + } + private func applyBorderWidth() { guard !skipStyling else { return } avatarImageView.layer.borderWidth = avatarBorderWidth @@ -101,6 +106,7 @@ class DefaultAvatarProvider: AvatarProviding { applyBorderWidth() applyBorderColor() applyCornerRadius() + applyAvatarActivityIndicatorTintColor() avatarImageView.clipsToBounds = true } @@ -116,6 +122,7 @@ class DefaultAvatarProvider: AvatarProviding { guard !skipStyling else { return } self.paletteType = paletteType applyBorderColor() + applyAvatarActivityIndicatorTintColor() avatarImageView.backgroundColor = paletteType.palette.avatar.background avatarImageView.overrideUserInterfaceStyle = paletteType.palette.preferredUserInterfaceStyle } diff --git a/Sources/GravatarUI/ProfileView/Placeholder/ProfileViewPlaceholderDisplaying.swift b/Sources/GravatarUI/ProfileView/Placeholder/ProfileViewPlaceholderDisplaying.swift index ed8417d1..37ce4436 100644 --- a/Sources/GravatarUI/ProfileView/Placeholder/ProfileViewPlaceholderDisplaying.swift +++ b/Sources/GravatarUI/ProfileView/Placeholder/ProfileViewPlaceholderDisplaying.swift @@ -87,7 +87,7 @@ class ProfileViewPlaceholderDisplayer: ProfileViewPlaceholderDisplaying { guard let elements else { return } for var element in elements { element.placeholderColor = placeholderColors.backgroundColor - if let element = element as? BackgroundColorPlaceholderDisplayer { + if let element = element as? AvatarPlaceholderDisplayer { element.originalBackgroundColor = paletteType.palette.avatar.background } if isShowing { diff --git a/Tests/GravatarUITests/LargeProfileSummaryViewTests.swift b/Tests/GravatarUITests/LargeProfileSummaryViewTests.swift index 8178c101..1ef5b4ce 100644 --- a/Tests/GravatarUITests/LargeProfileSummaryViewTests.swift +++ b/Tests/GravatarUITests/LargeProfileSummaryViewTests.swift @@ -49,6 +49,25 @@ final class LargeProfileSummaryViewTests: XCTestCase { assertSnapshot(of: containerView, as: .image, named: "\(interfaceStyle.name)") } + @MainActor + func testLargeProfileSummaryViewPlaceholdersCanShowCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard(), paletteType: .custom(Palette.testPalette)) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + assertSnapshot(of: containerView, as: .image) + } + + @MainActor + func testLargeProfileSummaryViewPlaceholdersCanHideCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard(), paletteType: .custom(Palette.testPalette)) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + cardView.update(with: TestProfileCardModel.summaryCard()) // set data and hide placeholders + assertSnapshot(of: containerView, as: .image) + } + @MainActor func testLargeProfileSummaryViewPlaceholderCanUpdateColors() throws { let interfaceStyle: UIUserInterfaceStyle = .light diff --git a/Tests/GravatarUITests/LargeProfileViewTests.swift b/Tests/GravatarUITests/LargeProfileViewTests.swift index e8acb941..bd6637d3 100644 --- a/Tests/GravatarUITests/LargeProfileViewTests.swift +++ b/Tests/GravatarUITests/LargeProfileViewTests.swift @@ -52,6 +52,27 @@ final class LargeProfileViewTests: XCTestCase { assertSnapshot(of: containerView, as: .image, named: "\(interfaceStyle.name)") } + @MainActor + func testLargeProfileViewPlaceholdersCanShowCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (cardView, containerView) = createViews(paletteType: .custom(Palette.testPalette)) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: TestProfileCardModel.fullCard()) + cardView.update(with: nil) // clear data and show placeholders + assertSnapshot(of: containerView, as: .image) + } + + @MainActor + func testLargeProfileViewPlaceholdersCanHideCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (cardView, containerView) = createViews(paletteType: .custom(Palette.testPalette)) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: TestProfileCardModel.fullCard()) + cardView.update(with: nil) // clear data and show placeholders + cardView.update(with: TestProfileCardModel.summaryCard()) // set data and hide placeholders + assertSnapshot(of: containerView, as: .image) + } + @MainActor func testLargeProfileViewPlaceholderCanUpdateColors() throws { let interfaceStyle: UIUserInterfaceStyle = .light diff --git a/Tests/GravatarUITests/ProfileSummaryViewTests.swift b/Tests/GravatarUITests/ProfileSummaryViewTests.swift index 38512ff4..5c229041 100644 --- a/Tests/GravatarUITests/ProfileSummaryViewTests.swift +++ b/Tests/GravatarUITests/ProfileSummaryViewTests.swift @@ -49,6 +49,27 @@ final class ProfileSummaryViewTests: XCTestCase { assertSnapshot(of: containerView, as: .image, named: "\(interfaceStyle.name)") } + @MainActor + func testProfileSummaryViewPlaceholdersCanShowCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard()) + cardView.paletteType = .custom(Palette.testPalette) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + assertSnapshot(of: containerView, as: .image) + } + + @MainActor + func testProfileSummaryViewPlaceholdersCanHideCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard()) + cardView.paletteType = .custom(Palette.testPalette) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + cardView.update(with: TestProfileCardModel.summaryCard()) // set data and hide placeholders + assertSnapshot(of: containerView, as: .image) + } + @MainActor func testProfileViewSummaryPlaceholderCanUpdateColors() throws { let interfaceStyle: UIUserInterfaceStyle = .light diff --git a/Tests/GravatarUITests/ProfileViewTests.swift b/Tests/GravatarUITests/ProfileViewTests.swift index 9064caf4..5bfa55cd 100644 --- a/Tests/GravatarUITests/ProfileViewTests.swift +++ b/Tests/GravatarUITests/ProfileViewTests.swift @@ -49,6 +49,27 @@ final class ProfileViewTests: XCTestCase { assertSnapshot(of: containerView, as: .image, named: "\(interfaceStyle.name)") } + @MainActor + func testProfileViewPlaceholdersCanShowCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard()) + cardView.paletteType = .custom(Palette.testPalette) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + assertSnapshot(of: containerView, as: .image) + } + + @MainActor + func testProfileViewPlaceholdersCanHideCustomPalette() throws { + let interfaceStyle: UIUserInterfaceStyle = .light + let (containerView, cardView) = createViews(model: TestProfileCardModel.summaryCard()) + cardView.paletteType = .custom(Palette.testPalette) + containerView.overrideUserInterfaceStyle = interfaceStyle + cardView.update(with: nil) // clear data and show placeholders + cardView.update(with: TestProfileCardModel.summaryCard()) // set data and hide placeholders + assertSnapshot(of: containerView, as: .image) + } + @MainActor func testProfileViewPlaceholderCanUpdateColors() throws { let interfaceStyle: UIUserInterfaceStyle = .light diff --git a/Tests/GravatarUITests/TestPalette.swift b/Tests/GravatarUITests/TestPalette.swift new file mode 100644 index 00000000..f33ee418 --- /dev/null +++ b/Tests/GravatarUITests/TestPalette.swift @@ -0,0 +1,28 @@ +import GravatarUI +import UIKit + +extension Palette { + static func testPalette() -> Palette { + Palette( + name: "TestPalette", + foreground: ForegroundColors( + primary: UIColor(red: 90 / 255, green: 88 / 255, blue: 88 / 255, alpha: 1), + + primarySlightlyDimmed: UIColor(red: 90 / 255, green: 88 / 255, blue: 88 / 255, alpha: 0.7), + secondary: UIColor(red: 9 / 255, green: 93 / 255, blue: 154 / 255, alpha: 1) + ), + background: BackgroundColors(primary: UIColor(red: 251 / 255, green: 216 / 255, blue: 183 / 255, alpha: 1)), + avatar: AvatarColors( + border: UIColor(red: 9 / 255, green: 93 / 255, blue: 154 / 255, alpha: 1), + background: UIColor(red: 9 / 255, green: 93 / 255, blue: 154 / 255, alpha: 0.25) + ), + border: UIColor(red: 255 / 255, green: 99 / 255, blue: 137 / 255, alpha: 1), + placeholder: PlaceholderColors( + backgroundColor: UIColor(red: 255 / 255, green: 179 / 255, blue: 186 / 255, alpha: 1), + loadingAnimationColors: [UIColor(red: 255 / 255, green: 179 / 255, blue: 186 / 255, alpha: 1), + UIColor(red: 255 / 255, green: 223 / 255, blue: 186 / 255, alpha: 1)] + ), + preferredUserInterfaceStyle: .light + ) + } +} diff --git a/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png new file mode 100644 index 00000000..f5ed6aea Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png new file mode 100644 index 00000000..7c2da3d4 Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/LargeProfileSummaryViewTests/testLargeProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanHideCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanHideCustomPalette.1.png new file mode 100644 index 00000000..63d0939a Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanHideCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanShowCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanShowCustomPalette.1.png new file mode 100644 index 00000000..e090e6c5 Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/LargeProfileViewTests/testLargeProfileViewPlaceholdersCanShowCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png new file mode 100644 index 00000000..e37d2e0a Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanHideCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png new file mode 100644 index 00000000..0d6b1b2a Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/ProfileSummaryViewTests/testProfileSummaryViewPlaceholdersCanShowCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanHideCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanHideCustomPalette.1.png new file mode 100644 index 00000000..9565f2bd Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanHideCustomPalette.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanShowCustomPalette.1.png b/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanShowCustomPalette.1.png new file mode 100644 index 00000000..f8888e15 Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/ProfileViewTests/testProfileViewPlaceholdersCanShowCustomPalette.1.png differ diff --git a/version.rb b/version.rb index 2f82760e..8d4d520f 100644 --- a/version.rb +++ b/version.rb @@ -1,3 +1,3 @@ module Gravatar - VERSION = '2.0.0'.freeze + VERSION = '2.0.1'.freeze end