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

Commit

Permalink
Mark couple of font method as main actor (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhieddine-El-Kaissi authored Oct 21, 2024
1 parent 895d983 commit 48d59c9
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 235 deletions.
8 changes: 4 additions & 4 deletions Sources/Thumbprint/Components/Pill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import UIKit
open class Pill: UIView, UIContentSizeCategoryAdjusting {
// MARK: - Class configuration

public struct Config {
public static var defaultHeight: CGFloat = 24.0
public static var defaultPadding: CGFloat = 12.0
public static var defaultTextStyle: Font.TextStyle = .title7
public struct Config: Sendable {
public static let defaultHeight: CGFloat = 24.0
public static let defaultPadding: CGFloat = 12.0
public static let defaultTextStyle: Font.TextStyle = .title7

public private(set) var height: CGFloat
public private(set) var padding: CGFloat
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Components/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private class KeyboardTracker {
* A wrapper around ToastView to handle the toast presentation and dismissal animations
*/
public class Toast: UIView {
public struct Theme: Equatable {
public struct Theme: Equatable, Sendable {
public let backgroundColor: UIColor
public let textColor: UIColor
public let iconColor: UIColor
Expand Down
9 changes: 4 additions & 5 deletions Sources/Thumbprint/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ public enum Font {
/// Font with text 3 style that supports scaling for accessibility.
public static var dynamicText3: UIFont { TextStyle.text3.dynamicFont }

// MARK: - Testing

/// Used by snapshot tests to forcefully apply the given trait collection. Do not use in application code.
public static var traitCollectionOverrideForTesting: UITraitCollection?

private static var didRegisterFonts = false

// MARK: - Testing
/// Used by snapshot tests to forcefully apply the given trait collection. Do not use in application code. same for nonisolated(unsafe)
public nonisolated(unsafe) static var traitCollectionOverrideForTesting: UITraitCollection?
}

// MARK: - Public Functions
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbprint/Icons.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public enum Icon: String, CaseIterable {
public enum Icon: String, CaseIterable, Sendable {
public enum Size: String, CaseIterable {
case tiny = "--tiny"
case small = "--small"
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 @@ -17,7 +17,7 @@ class AvatarTest: SnapshotTestCase {
.xLarge,
]

func testInitialsUser() {
@MainActor func testInitialsUser() {
let initials = [
"AYYYY",
"BOOOOOOO",
Expand All @@ -36,7 +36,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

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

func testInitialsEntity() {
@MainActor func testInitialsEntity() {
let initials = [
"AYYYY",
"BOOOOOOO",
Expand All @@ -68,7 +68,7 @@ class AvatarTest: SnapshotTestCase {
verifyViews(views: views)
}

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

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

func testOnlineUser() {
@MainActor func testOnlineUser() {
let image = UIImage(named: "eric",
in: Bundle.testing,
compatibleWith: nil)
Expand All @@ -109,13 +109,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: "D", 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 48d59c9

Please sign in to comment.