Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Remove UIView.init() is called in outside of the main thread #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Sources/Layouts/LabelLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,20 @@ open class LabelLayout<Label: UILabel>: BaseLayout<Label>, ConfigurableLayout {

public class LabelLayoutDefaults {
public static let defaultNumberOfLines = 0
public static let defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
private static var _defaultFont: UIFont?
public static var defaultFont: UIFont {
if Thread.isMainThread {
return UILabel().font ?? UIFont.systemFont(ofSize: 17)
}
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
DispatchQueue.main.async {
_defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
dispatchGroup.leave()
}
dispatchGroup.wait()
return _defaultFont!
}
public static let defaultAlignment = Alignment.topLeading
public static let defaultLineBreakMode = NSLineBreakMode.byTruncatingTail
public static let defaultFlexibility = Flexibility.flexible
Expand Down