Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
[AVATAR] Make entity avatar circular + dropping iphone se + OS versio…
Browse files Browse the repository at this point in the history
…n 17.5 (#169)

Make entity avatar circular: Figma
Dropping iphone se
OS version 17.5
Xcode 15.4
  • Loading branch information
Muhieddine-El-Kaissi authored Aug 28, 2024
1 parent 48ddd87 commit 2abc94e
Show file tree
Hide file tree
Showing 79 changed files with 11 additions and 134 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
# Adding additional destinations, schemes, etc. here will make GitHub run the steps
# on all combinations of them (e.g., if there are 2 destinations and 2 schemes, the
# test suite will get run 4 times).
destination: ["platform=iOS Simulator,OS=17.4,name=iPhone 15"]
destination: ["platform=iOS Simulator,OS=17.5,name=iPhone 15"]
scheme: ["Thumbprint"]
xcode: ["/Applications/Xcode_15.3.app"]
xcode: ["/Applications/Xcode_15.4.app"]
steps:
- name: 📥 Checkout
uses: actions/checkout@v2

- name: Select Xcode
run: sudo xcode-select -s "/Applications/Xcode_15.3.app"
run: sudo xcode-select -s "/Applications/Xcode_15.4.app"

- name: 🔎 Run lint checks
run: sh .github/scripts/lint.sh
Expand Down
121 changes: 2 additions & 119 deletions Sources/Thumbprint/Components/EntityAvatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,11 @@ import UIKit
*
* See Thumbprint Documentation on [Avatar]( https://thumbprint.design/components/avatar/react/ ).
*/
public final class EntityAvatar: UIView {
/**
The image displayed in the avatar image view
*/
public var image: UIImage? {
get {
avatar.image
}
set {
avatar.image = newValue
}
}

/**
Avatar Size
*/
public var size: Avatar.Size {
didSet {
updateSize()
}
}

/**
Boolean value that controls whether the online badge is shown or not
*/
public var isOnline: Bool {
didSet {
badgeView.isHidden = !isOnline
}
}

public final class EntityAvatar: UserAvatar {
/**
Any string longer that one character will be truncated for display.
*/
public var initials: String? {
public override var initials: String? {
didSet {
guard oldValue != initials else { return }
if let initials {
Expand All @@ -52,91 +22,4 @@ public final class EntityAvatar: UIView {
updateEmptyTheme()
}
}

/**
Used for accessibility label for the avatar.
*/
public var name: String? {
get {
accessibilityLabel
}
set {
accessibilityLabel = newValue
}
}

/**
Initializes an EntityAvatar used for displaying businesses, or service profiles.

- parameters:
- size: The initial `Avatar.Size` class for the component.
- initials: Any string longer that one character will be truncated for display.
- name: Used for accessibility label for the avatar.

This follows a similar structure to UserAvatar
*/
public init(size: Avatar.Size, initials: String? = nil, name: String? = nil, isOnline: Bool = false) {
self.size = size
self.avatar = Avatar(size: size)
self.badgeView = OnlineBadgeView()
self.isOnline = isOnline

super.init(frame: .zero)

self.initials = initials
self.name = name

setupViews()
updateSize()
updateEmptyTheme()
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// Enity Avatar - private
private let avatar: Avatar
private let badgeView: OnlineBadgeView
private var avatarHeightConstraint: Constraint?

public override var intrinsicContentSize: CGSize {
CGSize(width: size.dimension, height: size.dimension)
}

private func setupViews() {
avatar.layer.cornerRadius = 4.0
avatar.clipsToBounds = true
avatar.label.text = initials

addSubview(avatar)
avatar.snp.makeConstraints { make in
make.top.left.equalToSuperview()
avatarHeightConstraint = make.height.equalTo(size.dimension).constraint
make.width.equalTo(avatar.snp.height)
}

badgeView.isHidden = !isOnline
addSubview(badgeView)
}

private func updateEmptyTheme() {
avatar.emptyTheme = Avatar.backgroundColor(initials: initials)
}

private func updateSize() {
avatar.size = size

avatarHeightConstraint?.update(offset: size.dimension)
badgeView.snp.remakeConstraints { make in
let offset = ceil(size.badgeSize / 3)
make.top.equalToSuperview().offset(-offset)
make.right.equalToSuperview().offset(offset)
make.height.equalTo(size.badgeSize)
make.width.equalTo(badgeView.snp.height)
}

invalidateIntrinsicContentSize()
}
}
6 changes: 3 additions & 3 deletions Sources/Thumbprint/Components/UserAvatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit
*
* See Thumbprint Documentation on [Avatar]( https://thumbprint.design/components/avatar/react/ ).
*/
public final class UserAvatar: UIView {
public class UserAvatar: UIView {
/**
The image displayed in the avatar image view
*/
Expand Down Expand Up @@ -100,7 +100,7 @@ public final class UserAvatar: UIView {

// User Avatar - private

private let avatar: Avatar
let avatar: Avatar

public override var intrinsicContentSize: CGSize {
CGSize(width: size.dimension, height: size.dimension)
Expand Down Expand Up @@ -140,7 +140,7 @@ public final class UserAvatar: UIView {
setNeedsLayout()
}

private func updateEmptyTheme() {
func updateEmptyTheme() {
avatar.emptyTheme = Avatar.backgroundColor(initials: initials)
}

Expand Down
4 changes: 1 addition & 3 deletions Tests/ThumbprintTests/Snapshot/Components/AvatarTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ protocol AvatarView: UIView {

extension UserAvatar: AvatarView {}

extension EntityAvatar: AvatarView {}

class AvatarTest: SnapshotTestCase {
private static let allSizes: [Avatar.Size] = [
.xSmall,
Expand Down Expand Up @@ -113,7 +111,7 @@ class AvatarTest: SnapshotTestCase {

func testInitialization() {
let userAvatar = UserAvatar(size: .medium, initials: "DR", name: "Daniel Roth", isOnline: false)
let entityAvatar = EntityAvatar(size: .medium, initials: "DR", name: "Daniel Roth", isOnline: true)
let entityAvatar = EntityAvatar(size: .medium, initials: "D", name: "Daniel Roth", isOnline: true)
verifyViews(views: [userAvatar, entityAvatar])
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
8 changes: 2 additions & 6 deletions Tests/ThumbprintTests/Snapshot/Shared/SnapshotTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import XCTest
open class SnapshotTestCase: XCTestCase {
public enum WindowSize {
case `default`
case iPhoneSE
case iPhone8
case iPhone8Plus
case iPadPro9_7
case intrinsic
case defaultWidthIntrinsicHeight
case size(width: CGFloat, height: CGFloat, scaleHeightForContentSizeCategory: Bool = false)

public static var allPhones: [WindowSize] { [.iPhoneSE, .iPhone8, .iPhone8Plus] }
public static var allPhones: [WindowSize] { [.iPhone8, .iPhone8Plus] }
public static var all: [WindowSize] { .allPhones + [.iPadPro9_7] }

public var cgSize: CGSize {
switch self {
case .default:
WindowSize.iPhone8.cgSize
case .iPhoneSE:
CGSize(width: 320, height: 568)
case .iPhone8:
CGSize(width: 375, height: 667)
case .iPhone8Plus:
Expand Down Expand Up @@ -79,7 +76,6 @@ open class SnapshotTestCase: XCTestCase {

open override func setUp() {
super.setUp()

behavior = TestCaseBehavior()
}

Expand All @@ -98,7 +94,7 @@ open class SnapshotTestCase: XCTestCase {

static func verifyExpectedSnapshotTestDevice() {
let expectedDeviceName = "iPhone 15"
let expectedSystemVersion = "17.4"
let expectedSystemVersion = "17.5"

assert(UIDevice.current.name == expectedDeviceName, "Snapshot tests should be run on \(expectedDeviceName).")
assert(UIDevice.current.systemVersion == expectedSystemVersion, "Snapshot tests should be run on iOS \(expectedSystemVersion).")
Expand Down

0 comments on commit 2abc94e

Please sign in to comment.