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
  • Loading branch information
Muhieddine-El-Kaissi committed Jul 11, 2024
1 parent 70e9f0d commit ce0109b
Show file tree
Hide file tree
Showing 34 changed files with 189 additions and 184 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
12 changes: 6 additions & 6 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 Down
16 changes: 8 additions & 8 deletions Tests/ThumbprintTests/Snapshot/Components/AvatarTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AvatarTest: SnapshotTestCase {
.xLarge,
]

func testInitialsUser() {
@MainActor func testInitialsUser() {
let initials = [
"AYYYY",
"BOOOOOOO",
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ButtonRowTest: SnapshotTestCase {
.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
8 changes: 4 additions & 4 deletions Tests/ThumbprintTests/Snapshot/Components/ButtonTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class ButtonTest: SnapshotTestCase {
super.tearDown()
}

func testThemes() {
@MainActor func testThemes() {
themes.forEach { themeIdentifier, buttonConfig in
icons.forEach { iconIdentifier, iconConfig in
let size = WindowSize.intrinsic

func buttonMaker(postfix: String?) -> Button {
@MainActor func buttonMaker(postfix: String?) -> Button {
let button = Button(theme: buttonConfig.theme, size: buttonConfig.size)
var title = "\(themeIdentifier) \(iconIdentifier)"
if let postfix {
Expand Down Expand Up @@ -87,7 +87,7 @@ class ButtonTest: SnapshotTestCase {
}
}

func testSizes() {
@MainActor func testSizes() {
sizes.forEach { sizeIdentifier, buttonConfig in
icons.forEach { iconIdentifier, iconConfig in
button = Button(theme: buttonConfig.exampleTheme, size: buttonConfig.size)
Expand All @@ -102,7 +102,7 @@ class ButtonTest: SnapshotTestCase {
}
}

func testStretchWidth() {
@MainActor func testStretchWidth() {
button = Button(adjustsFontForContentSizeCategory: true)
button.title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium ornare magna et tristique."
button.icon = .init(.leading, image: Icon.notificationAlertsInfoFilledMedium.image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class CalendarPickerViewTest: SnapshotTestCase {
super.tearDown()
}

func testNoPreviousMonths() {
@MainActor func testNoPreviousMonths() {
calendarPicker.previousMonthCount = 0
calendarPicker.additionalMonthCount = 1
verify()
}

func testNoAdditionalMonths() {
@MainActor func testNoAdditionalMonths() {
calendarPicker.previousMonthCount = 1
calendarPicker.additionalMonthCount = 0
verify()
}

func testFixedCellHeight() {
@MainActor func testFixedCellHeight() {
calendarPicker.cellHeightMode = .fixed(70)
verify()
}

func testGoToDate() {
@MainActor func testGoToDate() {
calendarPicker.goToDate(Calendar.current.date(from: DateComponents(year: 2021, month: 1, day: 20))!, animated: false)
verify()
}

func testRecreateFigmaMock() {
@MainActor func testRecreateFigmaMock() {
calendarPicker.selectedDates = [
calendar.date(from: DateComponents(year: 2020, month: 1, day: 10))!,
]
Expand All @@ -63,7 +63,7 @@ class CalendarPickerViewTest: SnapshotTestCase {
verify()
}

func testMultipleSelection() {
@MainActor func testMultipleSelection() {
calendarPicker.allowsMultipleSelection = true
calendarPicker.selectedDates = [
calendar.date(from: DateComponents(year: 2020, month: 1, day: 4))!,
Expand All @@ -75,12 +75,12 @@ class CalendarPickerViewTest: SnapshotTestCase {
verify()
}

func testFixedHeight() {
@MainActor func testFixedHeight() {
calendarPicker.calendarHeightMode = .fixed
verify()
}

func testNonGregorianCalendar() {
@MainActor func testNonGregorianCalendar() {
calendar = Calendar(identifier: .hebrew)
calendar.locale = Locale(identifier: "he_IL")
calendarPicker = TestCalendarPickerView(visibleDate: today, calendar: calendar)
Expand All @@ -92,7 +92,7 @@ class CalendarPickerViewTest: SnapshotTestCase {
verify(identifier: "indian")
}

private func verify(identifier: String? = nil) {
@MainActor private func verify(identifier: String? = nil) {
verify(view: calendarPicker,
identifier: identifier,
contentSizeCategories: [.unspecified])
Expand Down
Loading

0 comments on commit ce0109b

Please sign in to comment.