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

Commit 7c2a7ff

Browse files
committed
Remove UIView.init() is called in outside of the main thread
1 parent 34abc8e commit 7c2a7ff

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sources/Layouts/LabelLayout.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,20 @@ open class LabelLayout<Label: UILabel>: BaseLayout<Label>, ConfigurableLayout {
165165

166166
public class LabelLayoutDefaults {
167167
public static let defaultNumberOfLines = 0
168-
public static let defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
168+
private static var _defaultFont: UIFont?
169+
public static var defaultFont: UIFont {
170+
if Thread.isMainThread {
171+
return UILabel().font ?? UIFont.systemFont(ofSize: 17)
172+
}
173+
let dispatchGroup = DispatchGroup()
174+
dispatchGroup.enter()
175+
DispatchQueue.main.async {
176+
_defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
177+
dispatchGroup.leave()
178+
}
179+
dispatchGroup.wait()
180+
return _defaultFont!
181+
}
169182
public static let defaultAlignment = Alignment.topLeading
170183
public static let defaultLineBreakMode = NSLineBreakMode.byTruncatingTail
171184
public static let defaultFlexibility = Flexibility.flexible

0 commit comments

Comments
 (0)