Pill View rendering, performance improvement part 2 (#1894)

* improvdement

* code improvement
This commit is contained in:
Mauro
2023-10-16 11:08:03 +02:00
committed by GitHub
parent 39e3328b02
commit d006ed1592
3 changed files with 19 additions and 10 deletions
@@ -24,7 +24,7 @@ protocol PillAttachmentViewProviderDelegate: AnyObject {
var roomContext: RoomScreenViewModel.Context? { get }
func registerPillView(_ pillView: UIView)
func invalidateTextAttachmentsDisplay(update: Bool)
func invalidateTextAttachmentsDisplay()
}
final class PillAttachmentViewProvider: NSTextAttachmentViewProvider {
@@ -44,7 +44,8 @@ final class PillAttachmentViewProvider: NSTextAttachmentViewProvider {
override func loadView() {
super.loadView()
guard let textAttachmentData = (textAttachment as? PillTextAttachment)?.pillData else {
guard let textAttachment = textAttachment as? PillTextAttachment,
let pillData = textAttachment.pillData else {
MXLog.failure("[PillAttachmentViewProvider]: attachment is missing data or not of expected class")
return
}
@@ -56,15 +57,16 @@ final class PillAttachmentViewProvider: NSTextAttachmentViewProvider {
context = PillContext.mock(type: .loadUser(isOwn: false))
imageProvider = MockMediaProvider()
} else if let roomContext = delegate?.roomContext {
context = PillContext(roomContext: roomContext, data: textAttachmentData)
context = PillContext(roomContext: roomContext, data: pillData)
imageProvider = roomContext.imageProvider
} else {
MXLog.failure("[PillAttachmentViewProvider]: missing room context")
return
}
let view = PillView(imageProvider: imageProvider, context: context) { [weak self] in
self?.delegate?.invalidateTextAttachmentsDisplay(update: true)
let view = PillView(imageProvider: imageProvider, context: context) { [weak self, weak textAttachment] in
textAttachment?.invalidateLastBounds()
self?.delegate?.invalidateTextAttachmentsDisplay()
}
let controller = UIHostingController(rootView: view)
controller.view.backgroundColor = .clear
@@ -93,5 +95,5 @@ extension WysiwygTextView: PillAttachmentViewProviderDelegate {
(mentionDisplayHelper as? ComposerMentionDisplayHelper)?.roomContext
}
func invalidateTextAttachmentsDisplay(update: Bool) { }
func invalidateTextAttachmentsDisplay() { }
}