Skip to content

Commit

Permalink
Merge release/2.0.0 into trunk (#287)
Browse files Browse the repository at this point in the history
* Small fixes on 2.0.0 (#284)

* Make the init public

* Fix placeholder displayer

* Set activity indicator tint color from palette

* Add snapshot tests for custom palette handling

* format

* Update version as 2.0.1 (#286)
  • Loading branch information
pinarol authored Jun 13, 2024
1 parent 9855eb4 commit 66803c8
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/GravatarUI/DesignSystem/Palette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,6 +106,7 @@ class DefaultAvatarProvider: AvatarProviding {
applyBorderWidth()
applyBorderColor()
applyCornerRadius()
applyAvatarActivityIndicatorTintColor()
avatarImageView.clipsToBounds = true
}

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIImageView> {
if let element = element as? AvatarPlaceholderDisplayer<UIView> {
element.originalBackgroundColor = paletteType.palette.avatar.background
}
if isShowing {
Expand Down
19 changes: 19 additions & 0 deletions Tests/GravatarUITests/LargeProfileSummaryViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions Tests/GravatarUITests/LargeProfileViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions Tests/GravatarUITests/ProfileSummaryViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions Tests/GravatarUITests/ProfileViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions Tests/GravatarUITests/TestPalette.swift
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gravatar
VERSION = '2.0.0'.freeze
VERSION = '2.0.1'.freeze
end

0 comments on commit 66803c8

Please sign in to comment.