mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -15,7 +15,10 @@ struct AttributedStringBuilderComponent: Hashable {
|
||||
|
||||
protocol AttributedStringBuilderProtocol {
|
||||
func fromPlain(_ string: String?) -> AttributedString?
|
||||
func fromPlain(_ string: String?) async -> AttributedString?
|
||||
|
||||
func fromHTML(_ htmlString: String?) -> AttributedString?
|
||||
func fromHTML(_ htmlString: String?) async -> AttributedString?
|
||||
|
||||
func blockquoteCoalescedComponentsFrom(_ attributedString: AttributedString?) -> [AttributedStringBuilderComponent]?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user