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

Commit

Permalink
Making more stuff thread safe
Browse files Browse the repository at this point in the history
f

more sendables
  • Loading branch information
Muhieddine-El-Kaissi committed Jul 12, 2024
1 parent 70e9f0d commit 072f5c1
Show file tree
Hide file tree
Showing 35 changed files with 215 additions and 210 deletions.
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Components/AlertBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class AlertBanner: UIView {
/**
* Themes
*/
public struct Theme: Equatable {
public struct Theme: Equatable, Sendable {
public let icon: UIImage
public let textColor: UIColor
public let backgroundColor: UIColor
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Components/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
*/

public final class Avatar: UIView {
public struct Size: Equatable {
public struct Size: Equatable, Sendable {
public let dimension: CGFloat
public let textFont: UIFont
public let badgeSize: CGFloat
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Components/Button.Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public extension Button {
self.init(textStyle: textStyle, contentPadding: contentPadding, iconTextSpacing: Space.one)
}

public static func height(for size: Size) -> CGFloat {
@MainActor public static func height(for size: Size) -> CGFloat {
size.textStyle.dynamicFont.lineHeight + size.contentPadding.height * 2.0
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TextFloatingActionButton: Control {
public static var module = Bundle.module
}

public struct Theme: Equatable {
public struct Theme: Equatable, Sendable {
let backgroundColor: UIColor
let borderColor: UIColor
let tintColor: UIColor
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Components/IconButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UIKit
public final class IconButton: Control {
// MARK: - Public Interface
/// Icon button theme
public struct Theme: Equatable {
public struct Theme: Equatable, Sendable {
let tintColor: UIColor
let activeTintColor: UIColor
let disabledTintColor: UIColor
Expand Down
6 changes: 3 additions & 3 deletions Sources/Thumbprint/Components/RadioGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class RadioGroup<Key> where Key: Hashable {
Sets the selection to the given key. Can be used to programmatically set the radio group's selection.
- Parameter value: The new selected key. Pass in `nil` to empty the selection.
*/
public func setSelection(_ value: Key?) {
@MainActor public func setSelection(_ value: Key?) {
let outgoingSelection = selectionSubject.value
guard value != outgoingSelection else {
return
Expand Down Expand Up @@ -69,7 +69,7 @@ public final class RadioGroup<Key> where Key: Hashable {
- Parameter radio: The `Radio` view associated in the UI with the given key.
- Parameter key: The key to be associated with the given radio.
*/
public func registerRadio(_ radio: Radio, forKey key: Key) {
@MainActor public func registerRadio(_ radio: Radio, forKey key: Key) {
assert(
!radioToKey.keys.contains(radio),
"Attempted to register radio object \(radio) with key \(key) already registered for key \(String(describing: radioToKey[radio]))"
Expand All @@ -85,7 +85,7 @@ public final class RadioGroup<Key> where Key: Hashable {
keyToRadio[key] = radio
}

@objc private func selectRadio(_ sender: Radio) {
@MainActor @objc private func selectRadio(_ sender: Radio) {
guard let selectedKey = radioToKey[sender] else {
assertionFailure("Attempted to select radio \(sender) not registered in radio group \(self)")
return
Expand Down
6 changes: 3 additions & 3 deletions Sources/Thumbprint/Components/RadioTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class RadioTableViewCellGroup {
self.selectedIndexPath = selectedIndexPath
}

public func register(indexPath: IndexPath) {
@MainActor public func register(indexPath: IndexPath) {
radioTableViewCellsPaths.insert(indexPath)
if tableView?.cellForRow(at: indexPath)?.isSelected == true {
selectedIndexPath = indexPath
Expand All @@ -119,12 +119,12 @@ public final class RadioTableViewCellGroup {
radioTableViewCellsPaths.contains(indexPath)
}

fileprivate func shouldReusedCellBeSelected(cell: RadioTableViewCell) -> Bool {
@MainActor fileprivate func shouldReusedCellBeSelected(cell: RadioTableViewCell) -> Bool {
guard let indexPath = tableView?.indexPath(for: cell) else { return false }
return indexPath == selectedIndexPath
}

fileprivate func didSelectCell(_ cell: RadioTableViewCell) {
@MainActor fileprivate func didSelectCell(_ cell: RadioTableViewCell) {
guard let indexPath = tableView?.indexPath(for: cell), indexPath != selectedIndexPath else { return }
if let selectedIndexPath {
tableView?.deselectRow(at: selectedIndexPath, animated: true)
Expand Down
1 change: 1 addition & 0 deletions Sources/Thumbprint/Components/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit

/// A set of utilities for configuring the appearance of tab bars
/// to match Thumbprint guidelines.
@MainActor
public enum TabBar {
private static var normalTitleTextAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: Color.black300,
Expand Down
5 changes: 3 additions & 2 deletions Sources/Thumbprint/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
*
* [Thumbprint Native Figma](https://www.figma.com/file/Z7xbBfwFUb2DGMd2Nptt0KoD/Thumbprint-Native?node-id=212%3A0 )
*/
@MainActor
public enum Font {
// MARK: - Static fonts

Expand Down Expand Up @@ -175,7 +176,7 @@ public extension Font {
}

/// Font with this text style that supports scaling for accessibility.
public var dynamicFont: UIFont {
@MainActor public var dynamicFont: UIFont {
Font.scaledFont(for: self)
}

Expand All @@ -185,7 +186,7 @@ public extension Font {
/// When using attributed strings, UIContentSizeCategoryAdusting.adjustsFontForContentSizeCategory
/// does not work, and therefore fonts must be configured with a specific trait collection
/// and updated any time the preferred content size category on the relevant view changes.
public func scaledFont(compatibleWith traitCollection: UITraitCollection) -> UIFont {
@MainActor public func scaledFont(compatibleWith traitCollection: UITraitCollection) -> UIFont {
Font.scaledFont(for: self, compatibleWith: traitCollection)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Utilities/UIView+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public extension UIView {
An option set for we can use when calling our utility methods to easily snap several edges of a view against
another view, usually its superview.
*/
struct SnapEdges: OptionSet {
struct SnapEdges: OptionSet, Sendable {
public let rawValue: Int

public init(rawValue: Int) {
Expand Down
14 changes: 7 additions & 7 deletions Tests/ThumbprintTests/Snapshot/Components/AlertBannerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Thumbprint
import UIKit

class AlertBannerTest: SnapshotTestCase {
func testInfo() {
@MainActor func testInfo() {
let alertBanner = Thumbprint.AlertBanner(
theme: .info,
message: "This is a sample message for an info banner.",
Expand All @@ -13,7 +13,7 @@ class AlertBannerTest: SnapshotTestCase {
verify(alertBanner: alertBanner)
}

func testWarning() {
@MainActor func testWarning() {
let alertBanner = Thumbprint.AlertBanner(
theme: .warning,
message: "This is a sample message for a warning banner.",
Expand All @@ -24,7 +24,7 @@ class AlertBannerTest: SnapshotTestCase {
verify(alertBanner: alertBanner)
}

func testCaution() {
@MainActor func testCaution() {
let alertBanner = Thumbprint.AlertBanner(
theme: .caution,
message: "This is a sample message for a caution banner.",
Expand All @@ -35,7 +35,7 @@ class AlertBannerTest: SnapshotTestCase {
verify(alertBanner: alertBanner)
}

func testMaxHeight() {
@MainActor func testMaxHeight() {
let alertBanner = Thumbprint.AlertBanner(
theme: .info,
message: "This is a sample message for an info banner.",
Expand All @@ -49,7 +49,7 @@ class AlertBannerTest: SnapshotTestCase {
verify(alertBanner: alertBanner)
}

func testUpdate() {
@MainActor func testUpdate() {
let alertBanner = Thumbprint.AlertBanner(
theme: .info,
message: "This is a sample message for an info banner.",
Expand All @@ -61,7 +61,7 @@ class AlertBannerTest: SnapshotTestCase {
verify(alertBanner: alertBanner)
}

func verify(alertBanner: AlertBanner) {
@MainActor func verify(alertBanner: AlertBanner) {
for widthToVerify in WindowSize.allPhones.map({ windowSize in windowSize.cgSize.width }) {
verify(
view: alertBanner,
Expand All @@ -70,7 +70,7 @@ class AlertBannerTest: SnapshotTestCase {
WindowSize.size(
width: widthToVerify,
height: .intrinsic
),
)
],
padding: 0
)
Expand Down
22 changes: 11 additions & 11 deletions Tests/ThumbprintTests/Snapshot/Components/AvatarTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class AvatarTest: SnapshotTestCase {
.small,
.medium,
.large,
.xLarge,
.xLarge
]

func testInitialsUser() {
@MainActor func testInitialsUser() {
let initials = [
"AYYYY",
"BOOOOOOO",
Expand All @@ -28,7 +28,7 @@ class AvatarTest: SnapshotTestCase {
"Eh!",
"FA",
"🥰😅",
"汉字汉",
"汉字汉"
]
let views: [UserAvatar] = initials.enumerated().map {
let avatar = UserAvatar(size: .medium)
Expand All @@ -38,7 +38,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testImageUser() {
@MainActor func testImageUser() {
let image = UIImage(named: "eric",
in: Bundle.testing,
compatibleWith: nil)
Expand All @@ -51,7 +51,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testInitialsEntity() {
@MainActor func testInitialsEntity() {
let initials = [
"AYYYY",
"BOOOOOOO",
Expand All @@ -60,7 +60,7 @@ class AvatarTest: SnapshotTestCase {
"Eh!",
"FA",
"🥰😅",
"汉字汉",
"汉字汉"
]
let views: [EntityAvatar] = initials.enumerated().map {
let avatar = EntityAvatar(size: .medium)
Expand All @@ -70,7 +70,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testImageEntity() {
@MainActor func testImageEntity() {
let image = UIImage(named: "eric",
in: Bundle.testing,
compatibleWith: nil)
Expand All @@ -83,7 +83,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testOnlineEntity() {
@MainActor func testOnlineEntity() {
let image = UIImage(named: "eric",
in: Bundle.testing,
compatibleWith: nil)
Expand All @@ -97,7 +97,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testOnlineUser() {
@MainActor func testOnlineUser() {
let image = UIImage(named: "eric",
in: Bundle.testing,
compatibleWith: nil)
Expand All @@ -111,13 +111,13 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

func testInitialization() {
@MainActor 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)
verifyViews(views: [userAvatar, entityAvatar])
}

func verifyViews(views: [AvatarView]) {
@MainActor func verifyViews(views: [AvatarView]) {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.alignment = .leading
Expand Down
6 changes: 3 additions & 3 deletions Tests/ThumbprintTests/Snapshot/Components/ButtonRowTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class ButtonRowTest: SnapshotTestCase {
"short": ("Title", "Title"),
"long": ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium ornare magna et tristique.", "Etiam egestas, metus id dignissim ultrices, odio enim imperdiet est, placerat ullamcorper augue ligula sed odio."),
"short-primary": ("Title", "Etiam egestas, metus id dignissim ultrices, odio enim imperdiet est, placerat ullamcorper augue ligula sed odio."),
"short-secondary": ("Etiam egestas, metus id dignissim ultrices, odio enim imperdiet est, placerat ullamcorper augue ligula sed odio.", "Title"),
"short-secondary": ("Etiam egestas, metus id dignissim ultrices, odio enim imperdiet est, placerat ullamcorper augue ligula sed odio.", "Title")
]
private let distributions: [ButtonRow.Distribution] = [
.equal,
.emphasis,
.minimal,
.minimal
]

func testAll() {
@MainActor func testAll() {
let buttonRow = ButtonRow(leftButton: Button(theme: .tertiary, adjustsFontForContentSizeCategory: false), rightButton: Button(adjustsFontForContentSizeCategory: false))

distributions.forEach { distribution in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Thumbprint
import UIKit

class ButtonStackTest: SnapshotTestCase {
func testOneButton() {
@MainActor func testOneButton() {
let button1 = Button(adjustsFontForContentSizeCategory: false)
button1.title = "Button 1"

verify(ButtonStack(buttons: [button1]))
}

func testTwoButtons() {
@MainActor func testTwoButtons() {
let button1 = Button(adjustsFontForContentSizeCategory: false)
button1.title = "Button 1"

Expand All @@ -19,7 +19,7 @@ class ButtonStackTest: SnapshotTestCase {
verify(ButtonStack(buttons: [button1, button2]))
}

func testThreeButtons() {
@MainActor func testThreeButtons() {
let button1 = Button(adjustsFontForContentSizeCategory: false)
button1.title = "Button 1"

Expand All @@ -32,7 +32,7 @@ class ButtonStackTest: SnapshotTestCase {
verify(ButtonStack(buttons: [button1, button2, button3]))
}

func verify(_ buttonStack: ButtonStack, file: StaticString = #filePath, line: UInt = #line) {
@MainActor func verify(_ buttonStack: ButtonStack, file: StaticString = #filePath, line: UInt = #line) {
verify(view: buttonStack,
identifier: "\(buttonStack.arrangedSubviews.count)buttons",
contentSizeCategories: [.unspecified],
Expand Down
Loading

0 comments on commit 072f5c1

Please sign in to comment.