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

Commit

Permalink
Remove UIView.init() is called in outside of the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
getogrand committed Jul 15, 2019
1 parent 34abc8e commit 5f4d4cf
Showing 1 changed file with 14 additions and 1 deletion.
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 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

0 comments on commit 5f4d4cf

Please sign in to comment.