Skip to content

Commit

Permalink
Merge pull request #1251 from wordpress-mobile/issue/fix_placeholder_…
Browse files Browse the repository at this point in the history
…images_dark_mode

Fix placeholder images when in dark mode
  • Loading branch information
SergioEstevao authored Dec 9, 2019
2 parents d8789be + 31fec22 commit c376a3a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Aztec/Assets/Media.xcassets/image.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
{
"idiom" : "universal",
"filename" : "gridicons-image.pdf"
},
{
"idiom" : "universal",
"filename" : "gridicons-image-dark.pdf",
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
]
}
],
"info" : {
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions Aztec/Classes/TextKit/MediaAttachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ open class MediaAttachment: NSTextAttachment {
needsNewAsset = refreshAsset
}

/// Invalidates the attachment and forces an update of the attachment image
open func refresh() {
needsNewAsset = true
retryCount = 0
image = nil
glyphImage = nil
}

/// Refresh attachment identifier
///
/// - Parameter identifier: new identifier
Expand Down
16 changes: 15 additions & 1 deletion Aztec/Classes/TextKit/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ open class TextView: UITextView {
}
}


public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
if #available(iOS 13.0, *) {
if let previous = previousTraitCollection, previous.hasDifferentColorAppearance(comparedTo: traitCollection) {
self.refreshMediaAttachments()
}
}
}
/// Blockquote Blocks Background Width.
///
@objc dynamic public var blockquoteBorderWidth: CGFloat {
Expand Down Expand Up @@ -1397,6 +1403,14 @@ open class TextView: UITextView {
notifyTextViewDidChange()
}

/// Forces a Refresh of all media attachment in the text view
open func refreshMediaAttachments() {
storage.enumerateAttachmentsOfType(MediaAttachment.self) { (attachment, range, _) in
attachment.refresh()
self.refresh(attachment, overlayUpdateOnly: false)
}
}

/// Replaces a Video attachment at the specified range
///
/// - Parameters:
Expand Down
4 changes: 4 additions & 0 deletions Example/AztecExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
F1D3610B20929F0200B4E7A5 /* WordPressEditor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1D3610420929E6D00B4E7A5 /* WordPressEditor.framework */; };
FF149F4A20E3C49A0070FECB /* imagesOverlays.html in Resources */ = {isa = PBXBuildFile; fileRef = FF149F4920E3C49A0070FECB /* imagesOverlays.html */; };
FF1FD05C20932EDE00186384 /* gutenberg.html in Resources */ = {isa = PBXBuildFile; fileRef = FF1FD05B20932EDE00186384 /* gutenberg.html */; };
FF5CDACD239E78B200CF235B /* failedMedia.html in Resources */ = {isa = PBXBuildFile; fileRef = FF5CDACC239E78B200CF235B /* failedMedia.html */; };
FF629DC9223BC418004C4106 /* videoShortcodes.html in Resources */ = {isa = PBXBuildFile; fileRef = FF629DC8223BC418004C4106 /* videoShortcodes.html */; };
FF9AF5481DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FF9AF5471DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard */; };
FFC41BDE20DBC7BA004DFB4D /* video.html in Resources */ = {isa = PBXBuildFile; fileRef = FFC41BDD20DBC7BA004DFB4D /* video.html */; };
Expand Down Expand Up @@ -155,6 +156,7 @@
F1D360FC20929E6D00B4E7A5 /* WordPressEditor.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = WordPressEditor.xcodeproj; path = ../WordPressEditor/WordPressEditor.xcodeproj; sourceTree = "<group>"; };
FF149F4920E3C49A0070FECB /* imagesOverlays.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = imagesOverlays.html; sourceTree = "<group>"; };
FF1FD05B20932EDE00186384 /* gutenberg.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = gutenberg.html; sourceTree = "<group>"; };
FF5CDACC239E78B200CF235B /* failedMedia.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = failedMedia.html; sourceTree = "<group>"; };
FF629DC8223BC418004C4106 /* videoShortcodes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = videoShortcodes.html; sourceTree = "<group>"; };
FF9AF5471DB0E4E200C42ED3 /* AttachmentDetailsViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = AttachmentDetailsViewController.storyboard; sourceTree = "<group>"; };
FFC41BDD20DBC7BA004DFB4D /* video.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = video.html; sourceTree = "<group>"; };
Expand Down Expand Up @@ -202,6 +204,7 @@
FF1FD05B20932EDE00186384 /* gutenberg.html */,
FFC41BDD20DBC7BA004DFB4D /* video.html */,
FF629DC8223BC418004C4106 /* videoShortcodes.html */,
FF5CDACC239E78B200CF235B /* failedMedia.html */,
);
path = SampleContent;
sourceTree = "<group>";
Expand Down Expand Up @@ -443,6 +446,7 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
59280F2A1D47CAF40083FB59 /* content.html in Resources */,
FF5CDACD239E78B200CF235B /* failedMedia.html in Resources */,
B5FB212A1FEC38470067D597 /* captions.html in Resources */,
FF1FD05C20932EDE00186384 /* gutenberg.html in Resources */,
59280F2B1D47CAF40083FB59 /* SampleText.rtf in Resources */,
Expand Down
18 changes: 15 additions & 3 deletions Example/Example/EditorDemoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ extension EditorDemoController {

}

// MARK: - TextViewAttachmentDelegate

extension EditorDemoController: TextViewAttachmentDelegate {

Expand Down Expand Up @@ -1087,7 +1088,7 @@ extension EditorDemoController: TextViewAttachmentDelegate {

func placeholderImage(for attachment: NSTextAttachment) -> UIImage {
let imageSize = CGSize(width:64, height:64)
let placeholderImage: UIImage
var placeholderImage: UIImage
switch attachment {
case _ as ImageAttachment:
placeholderImage = Gridicon.iconOfType(.image, withSize: imageSize)
Expand All @@ -1096,7 +1097,9 @@ extension EditorDemoController: TextViewAttachmentDelegate {
default:
placeholderImage = Gridicon.iconOfType(.attachment, withSize: imageSize)
}

if #available(iOS 13.0, *) {
placeholderImage = placeholderImage.withTintColor(.label)
}
return placeholderImage
}

Expand Down Expand Up @@ -1501,10 +1504,19 @@ private extension EditorDemoController

extension EditorDemoController {

static var tintedMissingImage: UIImage = {
if #available(iOS 13.0, *) {
return Gridicon.iconOfType(.image).withTintColor(.label)
} else {
// Fallback on earlier versions
return Gridicon.iconOfType(.image)
}
}()

struct Constants {
static let defaultContentFont = UIFont.systemFont(ofSize: 14)
static let defaultHtmlFont = UIFont.systemFont(ofSize: 24)
static let defaultMissingImage = Gridicon.iconOfType(.image)
static let defaultMissingImage = tintedMissingImage
static let formatBarIconSize = CGSize(width: 20.0, height: 20.0)
static let headers = [Header.HeaderType.none, .h1, .h2, .h3, .h4, .h5, .h6]
static let lists = [TextList.Style.unordered, .ordered]
Expand Down
5 changes: 5 additions & 0 deletions Example/Example/SampleContent/failedMedia.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Video</h3>
<video src="https://nothere.mp4" poster="notthere.jpg" alt="Another video with bunnies"></video>

<h3>Image</h3>
<img src="https://nothere.jpeg" alt="Coyote" class="alignleft"/>
1 change: 1 addition & 0 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ViewController: UITableViewController
DemoRow(title: "Captions Demo", action: { self.showEditorDemo(filename: "captions") }),
DemoRow(title: "Image Overlays", action: { self.showEditorDemo(filename: "imagesOverlays") }),
DemoRow(title: "Video Demo", action: { self.showEditorDemo(filename: "video", wordPressMode: false) }),
DemoRow(title: "Failed Media", action: { self.showEditorDemo(filename: "failedMedia") }),
DemoRow(title: "Empty Demo", action: { self.showEditorDemo() })
]
),
Expand Down

0 comments on commit c376a3a

Please sign in to comment.