Fix vector-im/element-x-ios/issues/134 - Prevent home screen room last message attributed string from being computed on every update

Add async/await methods to the AttributedStringBuilder and adopt them throughout the app
This commit is contained in:
Stefan Ceriu
2022-07-22 10:25:17 +03:00
committed by GitHub
parent 2f4fb81aa5
commit e1eee9465e
11 changed files with 147 additions and 89 deletions
@@ -32,6 +32,12 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
}
}
func fromPlain(_ string: String?) async -> AttributedString? {
await Task.detached {
fromPlain(string)
}.value
}
func fromPlain(_ string: String?) -> AttributedString? {
guard let string = string else {
return nil
@@ -44,6 +50,12 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
return try? AttributedString(mutableAttributedString, including: \.elementX)
}
func fromHTML(_ htmlString: String?) async -> AttributedString? {
await Task.detached {
fromHTML(htmlString)
}.value
}
// Do not use the default HTML renderer of NSAttributedString because this method
// runs on the UI thread which we want to avoid because renderHTMLString is called
// most of the time from a background thread.