From 8b7acc3cd641020c2945afbdb0ae8cc643fa8b9f Mon Sep 17 00:00:00 2001 From: guohui Date: Wed, 22 Nov 2017 22:40:28 +0800 Subject: [PATCH] fix LabelLayout async init used UILabel(). --- LayoutKitTests/LabelLayoutTests.swift | 11 +++++++++++ Sources/Layouts/LabelLayout.swift | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/LayoutKitTests/LabelLayoutTests.swift b/LayoutKitTests/LabelLayoutTests.swift index f7eed7c2..309371c9 100644 --- a/LayoutKitTests/LabelLayoutTests.swift +++ b/LayoutKitTests/LabelLayoutTests.swift @@ -60,6 +60,17 @@ class LabelLayoutTests: XCTestCase { XCTAssertEqual(arrangement.makeViews().frame.size, label.intrinsicContentSize) } + + func testAsyncAttributedLabel() { + DispatchQueue.global(qos: .userInitiated).async { + let attributedText = NSAttributedString(string: "Async", attributes: [NSAttributedStringKey.font: UIFont.helvetica(size: 42)]) + let arrangement = LabelLayout(attributedText: attributedText).arrangement() + DispatchQueue.main.async { + let label = UILabel(attributedText: attributedText, font: UIFont.helvetica(size: 42)) + XCTAssertEqual(arrangement.makeViews().frame.size, label.intrinsicContentSize) + } + } + } func testTwoLineLabel() { let text = "Nick Snyder" diff --git a/Sources/Layouts/LabelLayout.swift b/Sources/Layouts/LabelLayout.swift index b1fa4ccb..8c383acc 100644 --- a/Sources/Layouts/LabelLayout.swift +++ b/Sources/Layouts/LabelLayout.swift @@ -112,7 +112,7 @@ open class LabelLayout: BaseLayout