Skip to content

Commit c376a3a

Browse files
Merge pull request #1251 from wordpress-mobile/issue/fix_placeholder_images_dark_mode
Fix placeholder images when in dark mode
2 parents d8789be + 31fec22 commit c376a3a

8 files changed

Lines changed: 58 additions & 4 deletions

File tree

Aztec/Assets/Media.xcassets/image.imageset/Contents.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
{
44
"idiom" : "universal",
55
"filename" : "gridicons-image.pdf"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "gridicons-image-dark.pdf",
10+
"appearances" : [
11+
{
12+
"appearance" : "luminosity",
13+
"value" : "dark"
14+
}
15+
]
616
}
717
],
818
"info" : {
Binary file not shown.

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,13 @@ open class TextView: UITextView {
317317
}
318318
}
319319

320-
320+
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
321+
if #available(iOS 13.0, *) {
322+
if let previous = previousTraitCollection, previous.hasDifferentColorAppearance(comparedTo: traitCollection) {
323+
self.refreshMediaAttachments()
324+
}
325+
}
326+
}
321327
/// Blockquote Blocks Background Width.
322328
///
323329
@objc dynamic public var blockquoteBorderWidth: CGFloat {
@@ -1397,6 +1403,14 @@ open class TextView: UITextView {
13971403
notifyTextViewDidChange()
13981404
}
13991405

1406+
/// Forces a Refresh of all media attachment in the text view
1407+
open func refreshMediaAttachments() {
1408+
storage.enumerateAttachmentsOfType(MediaAttachment.self) { (attachment, range, _) in
1409+
attachment.refresh()
1410+
self.refresh(attachment, overlayUpdateOnly: false)
1411+
}
1412+
}
1413+
14001414
/// Replaces a Video attachment at the specified range
14011415
///
14021416
/// - Parameters:

Example/AztecExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
F1D3610B20929F0200B4E7A5 /* WordPressEditor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1D3610420929E6D00B4E7A5 /* WordPressEditor.framework */; };
4040
FF149F4A20E3C49A0070FECB /* imagesOverlays.html in Resources */ = {isa = PBXBuildFile; fileRef = FF149F4920E3C49A0070FECB /* imagesOverlays.html */; };
4141
FF1FD05C20932EDE00186384 /* gutenberg.html in Resources */ = {isa = PBXBuildFile; fileRef = FF1FD05B20932EDE00186384 /* gutenberg.html */; };
42+
FF5CDACD239E78B200CF235B /* failedMedia.html in Resources */ = {isa = PBXBuildFile; fileRef = FF5CDACC239E78B200CF235B /* failedMedia.html */; };
4243
FF629DC9223BC418004C4106 /* videoShortcodes.html in Resources */ = {isa = PBXBuildFile; fileRef = FF629DC8223BC418004C4106 /* videoShortcodes.html */; };
4344
FF9AF5481DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FF9AF5471DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard */; };
4445
FFC41BDE20DBC7BA004DFB4D /* video.html in Resources */ = {isa = PBXBuildFile; fileRef = FFC41BDD20DBC7BA004DFB4D /* video.html */; };
@@ -155,6 +156,7 @@
155156
F1D360FC20929E6D00B4E7A5 /* WordPressEditor.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = WordPressEditor.xcodeproj; path = ../WordPressEditor/WordPressEditor.xcodeproj; sourceTree = "<group>"; };
156157
FF149F4920E3C49A0070FECB /* imagesOverlays.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = imagesOverlays.html; sourceTree = "<group>"; };
157158
FF1FD05B20932EDE00186384 /* gutenberg.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = gutenberg.html; sourceTree = "<group>"; };
159+
FF5CDACC239E78B200CF235B /* failedMedia.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = failedMedia.html; sourceTree = "<group>"; };
158160
FF629DC8223BC418004C4106 /* videoShortcodes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = videoShortcodes.html; sourceTree = "<group>"; };
159161
FF9AF5471DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = AttachmentDetailsViewController.storyboard; sourceTree = "<group>"; };
160162
FFC41BDD20DBC7BA004DFB4D /* video.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = video.html; sourceTree = "<group>"; };
@@ -202,6 +204,7 @@
202204
FF1FD05B20932EDE00186384 /* gutenberg.html */,
203205
FFC41BDD20DBC7BA004DFB4D /* video.html */,
204206
FF629DC8223BC418004C4106 /* videoShortcodes.html */,
207+
FF5CDACC239E78B200CF235B /* failedMedia.html */,
205208
);
206209
path = SampleContent;
207210
sourceTree = "<group>";
@@ -443,6 +446,7 @@
443446
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
444447
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
445448
59280F2A1D47CAF40083FB59 /* content.html in Resources */,
449+
FF5CDACD239E78B200CF235B /* failedMedia.html in Resources */,
446450
B5FB212A1FEC38470067D597 /* captions.html in Resources */,
447451
FF1FD05C20932EDE00186384 /* gutenberg.html in Resources */,
448452
59280F2B1D47CAF40083FB59 /* SampleText.rtf in Resources */,

Example/Example/EditorDemoController.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ extension EditorDemoController {
10551055

10561056
}
10571057

1058+
// MARK: - TextViewAttachmentDelegate
10581059

10591060
extension EditorDemoController: TextViewAttachmentDelegate {
10601061

@@ -1087,7 +1088,7 @@ extension EditorDemoController: TextViewAttachmentDelegate {
10871088

10881089
func placeholderImage(for attachment: NSTextAttachment) -> UIImage {
10891090
let imageSize = CGSize(width:64, height:64)
1090-
let placeholderImage: UIImage
1091+
var placeholderImage: UIImage
10911092
switch attachment {
10921093
case _ as ImageAttachment:
10931094
placeholderImage = Gridicon.iconOfType(.image, withSize: imageSize)
@@ -1096,7 +1097,9 @@ extension EditorDemoController: TextViewAttachmentDelegate {
10961097
default:
10971098
placeholderImage = Gridicon.iconOfType(.attachment, withSize: imageSize)
10981099
}
1099-
1100+
if #available(iOS 13.0, *) {
1101+
placeholderImage = placeholderImage.withTintColor(.label)
1102+
}
11001103
return placeholderImage
11011104
}
11021105

@@ -1501,10 +1504,19 @@ private extension EditorDemoController
15011504

15021505
extension EditorDemoController {
15031506

1507+
static var tintedMissingImage: UIImage = {
1508+
if #available(iOS 13.0, *) {
1509+
return Gridicon.iconOfType(.image).withTintColor(.label)
1510+
} else {
1511+
// Fallback on earlier versions
1512+
return Gridicon.iconOfType(.image)
1513+
}
1514+
}()
1515+
15041516
struct Constants {
15051517
static let defaultContentFont = UIFont.systemFont(ofSize: 14)
15061518
static let defaultHtmlFont = UIFont.systemFont(ofSize: 24)
1507-
static let defaultMissingImage = Gridicon.iconOfType(.image)
1519+
static let defaultMissingImage = tintedMissingImage
15081520
static let formatBarIconSize = CGSize(width: 20.0, height: 20.0)
15091521
static let headers = [Header.HeaderType.none, .h1, .h2, .h3, .h4, .h5, .h6]
15101522
static let lists = [TextList.Style.unordered, .ordered]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h3>Video</h3>
2+
<video src="https://nothere.mp4" poster="notthere.jpg" alt="Another video with bunnies"></video>
3+
4+
<h3>Image</h3>
5+
<img src="https://nothere.jpeg" alt="Coyote" class="alignleft"/>

Example/Example/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ViewController: UITableViewController
1919
DemoRow(title: "Captions Demo", action: { self.showEditorDemo(filename: "captions") }),
2020
DemoRow(title: "Image Overlays", action: { self.showEditorDemo(filename: "imagesOverlays") }),
2121
DemoRow(title: "Video Demo", action: { self.showEditorDemo(filename: "video", wordPressMode: false) }),
22+
DemoRow(title: "Failed Media", action: { self.showEditorDemo(filename: "failedMedia") }),
2223
DemoRow(title: "Empty Demo", action: { self.showEditorDemo() })
2324
]
2425
),

0 commit comments

Comments
 (0)