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
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhieddine-El-Kaissi committed Oct 16, 2024
1 parent 895d983 commit 1aa4dc0
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 190 deletions.
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
34 changes: 17 additions & 17 deletions Sources/Thumbprint/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,42 @@ public enum Font {
// MARK: - Fonts that support scaling for accessibility.

/// Font with title 1 style that supports scaling for accessibility.
public static var dynamicTitle1: UIFont { TextStyle.title1.dynamicFont }
@MainActor public static var dynamicTitle1: UIFont { TextStyle.title1.dynamicFont }

/// Font with title 2 style that supports scaling for accessibility.
public static var dynamicTitle2: UIFont { TextStyle.title2.dynamicFont }
@MainActor public static var dynamicTitle2: UIFont { TextStyle.title2.dynamicFont }

/// Font with title 3 style that supports scaling for accessibility.
public static var dynamicTitle3: UIFont { TextStyle.title3.dynamicFont }
@MainActor public static var dynamicTitle3: UIFont { TextStyle.title3.dynamicFont }

/// Font with title 4 style that supports scaling for accessibility.
public static var dynamicTitle4: UIFont { TextStyle.title4.dynamicFont }
@MainActor public static var dynamicTitle4: UIFont { TextStyle.title4.dynamicFont }

/// Font with title 5 style that supports scaling for accessibility.
public static var dynamicTitle5: UIFont { TextStyle.title5.dynamicFont }
@MainActor public static var dynamicTitle5: UIFont { TextStyle.title5.dynamicFont }

/// Font with title 6 style that supports scaling for accessibility.
public static var dynamicTitle6: UIFont { TextStyle.title6.dynamicFont }
@MainActor public static var dynamicTitle6: UIFont { TextStyle.title6.dynamicFont }

/// Font with title 7 style that supports scaling for accessibility.
public static var dynamicTitle7: UIFont { TextStyle.title7.dynamicFont }
@MainActor public static var dynamicTitle7: UIFont { TextStyle.title7.dynamicFont }

/// Font with title 8 style that supports scaling for accessibility.
public static var dynamicTitle8: UIFont { TextStyle.title8.dynamicFont }
@MainActor public static var dynamicTitle8: UIFont { TextStyle.title8.dynamicFont }

/// Font with text 1 style that supports scaling for accessibility.
public static var dynamicText1: UIFont { TextStyle.text1.dynamicFont }
@MainActor public static var dynamicText1: UIFont { TextStyle.text1.dynamicFont }

/// Font with text 2 style that supports scaling for accesssibility.
public static var dynamicText2: UIFont { TextStyle.text2.dynamicFont }
@MainActor public static var dynamicText2: UIFont { TextStyle.text2.dynamicFont }

/// Font with text 3 style that supports scaling for accessibility.
public static var dynamicText3: UIFont { TextStyle.text3.dynamicFont }
@MainActor 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?
@MainActor public static var traitCollectionOverrideForTesting: UITraitCollection?

private static var didRegisterFonts = false
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public extension Font {
didRegisterFonts = true
}

static func scaledValue(_ value: CGFloat, for style: TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> CGFloat {
@MainActor static func scaledValue(_ value: CGFloat, for style: TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> CGFloat {
UIFontMetrics(forTextStyle: style.uiFontTextStyle).scaledValue(for: value, compatibleWith: resolvedTraits(for: traitCollection))
}
}
Expand Down Expand Up @@ -175,7 +175,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 +185,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 Expand Up @@ -289,7 +289,7 @@ public extension UIContentSizeCategoryAdjusting {

// MARK: - Private
private extension Font {
private static func resolvedTraits(for traitCollection: UITraitCollection?) -> UITraitCollection? {
@MainActor private static func resolvedTraits(for traitCollection: UITraitCollection?) -> UITraitCollection? {
switch (traitCollection, traitCollectionOverrideForTesting) {
case (.none, .none):
nil
Expand All @@ -305,7 +305,7 @@ private extension Font {
}
}

static func scaledFont(for style: TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont {
@MainActor static func scaledFont(for style: TextStyle, compatibleWith traitCollection: UITraitCollection? = nil) -> UIFont {
let fontMetrics = UIFontMetrics(forTextStyle: style.uiFontTextStyle)
let scaledFont = fontMetrics.scaledFont(for: style.uiFont, compatibleWith: resolvedTraits(for: traitCollection))
switch (traitCollection, traitCollectionOverrideForTesting) {
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 1aa4dc0

Please sign in to comment.