Skip to content

Commit d8ae109

Browse files
committed
Forces a refresh of all media attachment when Interface appearance changes.
1 parent 67e48fc commit d8ae109

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Aztec/Classes/TextKit/MediaAttachment.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ open class MediaAttachment: NSTextAttachment {
186186
needsNewAsset = refreshAsset
187187
}
188188

189+
/// Invalidates the attachment and forces an update of the attachment image
190+
open func refresh() {
191+
needsNewAsset = true
192+
retryCount = 0
193+
image = nil
194+
glyphImage = nil
195+
}
196+
189197
/// Refresh attachment identifier
190198
///
191199
/// - Parameter identifier: new identifier

Aztec/Classes/TextKit/TextView.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ open class TextView: UITextView {
306306
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
307307
if #available(iOS 13.0, *) {
308308
if let previous = previousTraitCollection, previous.hasDifferentColorAppearance(comparedTo: traitCollection) {
309-
self.setHTML(self.getHTML())
309+
self.refreshMediaAttachments()
310310
}
311311
}
312312
}
@@ -1389,6 +1389,14 @@ open class TextView: UITextView {
13891389
notifyTextViewDidChange()
13901390
}
13911391

1392+
/// Forces a Refresh of all media attachment in the text view
1393+
open func refreshMediaAttachments() {
1394+
storage.enumerateAttachmentsOfType(MediaAttachment.self) { (attachment, range, _) in
1395+
attachment.refresh()
1396+
self.refresh(attachment, overlayUpdateOnly: false)
1397+
}
1398+
}
1399+
13921400
/// Replaces a Video attachment at the specified range
13931401
///
13941402
/// - Parameters:

0 commit comments

Comments
 (0)