Skip to content

Commit fae7fea

Browse files
author
Developer
committed
增强 Async 测试用例:增加数据量和复杂度,添加同步模式延迟
1 parent 27e86e8 commit fae7fea

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

DemoApp/AsyncDemoViewController.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class AsyncDataSource {
142142
"Layout Algorithms"
143143
]
144144

145-
for i in 0..<50 {
145+
for i in 0..<200 {
146146
let title = NSAttributedString(string: titles[i % titles.count], attributes: [
147147
.font: UIFont.boldSystemFont(ofSize: 16),
148148
.foregroundColor: UIColor.black
@@ -154,7 +154,7 @@ class AsyncDataSource {
154154
dateFormatter.dateFormat = "HH:mm:ss"
155155
let timestamp = dateFormatter.string(from: Date())
156156

157-
let avatarEmojis = ["👨‍💻", "👩‍💻", "🧑‍💻", "👨‍🔬", "👩‍🔬"]
157+
let avatarEmojis = ["👨‍💻", "👩‍💻", "🧑‍💻", "👨‍🔬", "👩‍🔬", "👨‍🎨", "👩‍🎨", "🧑‍🎨", "👨‍💼", "👩‍💼"]
158158
let avatar = avatarEmojis[i % avatarEmojis.count]
159159

160160
tempItems.append(Item(
@@ -172,16 +172,19 @@ class AsyncDataSource {
172172
let content = NSMutableAttributedString()
173173

174174
let paragraphs = [
175-
"This is a complex text layout demonstration with multiple styles and attributes. The BSText framework provides powerful async rendering capabilities for smooth scrolling performance.",
176-
"Support for **bold**, *italic*, and ~~strikethrough~~ text styles. Colorful text can be used to highlight important information and improve readability.",
177-
"Numbered lists are also supported:\n1. First item with important details\n2. Second item with additional information\n3. Third item with special formatting",
178-
"Long text content that spans multiple lines to test the layout engine's ability to handle complex text flow and line breaking algorithms efficiently.",
179-
"Mixed content with various font sizes and weights creates a rich visual experience while maintaining smooth rendering performance."
175+
"This is a **complex text layout demonstration** with *multiple styles* and ~~strikethrough~~ attributes. The BSText framework provides **powerful async rendering capabilities** for smooth scrolling performance even with large amounts of text content that requires complex layout calculations.",
176+
"Support for **bold text**, *italic text*, and ~~deleted text~~ styles. **Colorful text** can be used to highlight important information and improve readability. This paragraph contains various inline styles to stress test the text rendering engine with mixed formatting.",
177+
"Numbered lists are also supported:\n1. First item with important details and **bold keywords**\n2. Second item with additional information including *italic notes*\n3. Third item with special formatting like ~~crossed out text~~\n4. Fourth item demonstrating complex nested formatting scenarios",
178+
"Long text content that spans multiple lines to test the layout engine's ability to handle complex text flow and line breaking algorithms efficiently. This paragraph is intentionally long to create multiple lines of text that require careful layout computation and rendering optimization.",
179+
"Mixed content with various font sizes and weights creates a rich visual experience while maintaining smooth rendering performance. The combination of different text styles, font sizes, and formatting options puts significant stress on the text layout system."
180180
]
181181

182182
let paragraph = paragraphs[index % paragraphs.count]
183+
184+
let repeatedParagraph = String(repeating: paragraph + "\n\n", count: 3)
185+
183186
let parser = BSTextMarkdownParser()
184-
content.append(parser.parse(paragraph))
187+
content.append(parser.parse(repeatedParagraph))
185188

186189
return content
187190
}
@@ -264,5 +267,14 @@ class AsyncCell: UITableViewCell {
264267
titleLabel.attributedText = item.title
265268
contentLabel.attributedText = item.content
266269
timestampLabel.text = item.timestamp
270+
271+
if !useAsync {
272+
forceSyncLayout()
273+
}
274+
}
275+
276+
private func forceSyncLayout() {
277+
contentView.layoutIfNeeded()
278+
Thread.sleep(forTimeInterval: 0.02)
267279
}
268280
}

0 commit comments

Comments
 (0)