Separate background suppression from symbol processing. Fixes #2646 & Fixes #2635

This commit is contained in:
Maurice Parker 2020-12-06 14:25:22 -06:00
parent 2f5486158c
commit ef18600acc
11 changed files with 40 additions and 21 deletions

View File

@ -155,7 +155,7 @@ struct AppAssets {
let image = NSImage(systemSymbolName: "folder", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, preferredColor: preferredColor.cgColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.folderName)!)
}
@ -223,7 +223,7 @@ struct AppAssets {
}()
static var searchFeedImage: IconImage = {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true)
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true, isBackgroundSupressed: true)
}()
@available(macOS 11.0, *)
@ -251,9 +251,9 @@ struct AppAssets {
let image = NSImage(systemSymbolName: "star.fill", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "StarColor")!
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, preferredColor: preferredColor.cgColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true)
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true)
}
}()
@ -274,9 +274,9 @@ struct AppAssets {
let image = NSImage(systemSymbolName: "sun.max.fill", accessibilityDescription: nil)!
let preferredColor = NSColor.orange
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, preferredColor: preferredColor.cgColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true)
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true)
}
}()
@ -285,9 +285,9 @@ struct AppAssets {
let image = NSImage(systemSymbolName: "largecircle.fill.circle", accessibilityDescription: nil)!
let preferredColor = NSColor(named: "AccentColor")!
let coloredImage = image.tinted(with: preferredColor)
return IconImage(coloredImage, isSymbol: true, preferredColor: preferredColor.cgColor)
return IconImage(coloredImage, isSymbol: true, isBackgroundSupressed: true, preferredColor: preferredColor.cgColor)
} else {
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isSymbol: true)
return IconImage(RSImage(named: NSImage.smartBadgeTemplateName)!, isBackgroundSupressed: true)
}
}()

View File

@ -84,7 +84,7 @@ final class IconView: NSView {
}
override func draw(_ dirtyRect: NSRect) {
guard !(iconImage?.isSymbol ?? true) else { return }
guard !(iconImage?.isBackgroundSupressed ?? false) else { return }
guard hasExposedVerticalBackground || !isDisconcernable else { return }
let color = NSApplication.shared.effectiveAppearance.isDarkMode ? IconView.darkBackgroundColor : IconView.lightBackgroundColor

View File

@ -143,14 +143,14 @@ private extension SidebarCell {
if let iconImage = iconImage, iconImage.isSymbol {
if backgroundStyle != .normal {
let image = iconImage.image.tinted(with: .white)
updatedIconImage = IconImage(image, isSymbol: true)
updatedIconImage = IconImage(image, isSymbol: iconImage.isSymbol, isBackgroundSupressed: iconImage.isBackgroundSupressed)
} else {
if let preferredColor = iconImage.preferredColor {
let image = iconImage.image.tinted(with: NSColor(cgColor: preferredColor)!)
updatedIconImage = IconImage(image, isSymbol: true)
updatedIconImage = IconImage(image, isSymbol: iconImage.isSymbol, isBackgroundSupressed: iconImage.isBackgroundSupressed)
} else {
let image = iconImage.image.tinted(with: .controlAccentColor)
updatedIconImage = IconImage(image, isSymbol: true)
updatedIconImage = IconImage(image, isSymbol: iconImage.isSymbol, isBackgroundSupressed: iconImage.isBackgroundSupressed)
}
}
}

View File

@ -55,6 +55,10 @@ final class IconView: UIView {
return imageView.image?.isSymbolImage ?? false
}
private var isBackgroundSuppressed: Bool {
return imageView.image?.isBackgroundSuppressed ?? false
}
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
@ -75,7 +79,7 @@ final class IconView: UIView {
override func layoutSubviews() {
imageView.setFrameIfNotEqual(rectForImageView())
if (iconImage != nil && isVerticalBackgroundExposed && !isSymbolImage) || !isDisconcernable {
if (iconImage != nil && isVerticalBackgroundExposed) || !isDisconcernable {
backgroundColor = AppAssets.uiIconBackgroundColor
} else {
backgroundColor = nil

View File

@ -26,12 +26,14 @@ final class IconImage {
let image: RSImage
let isSymbol: Bool
let isBackgroundSupressed: Bool
let preferredColor: CGColor?
init(_ image: RSImage, isSymbol: Bool = false, preferredColor: CGColor? = nil) {
init(_ image: RSImage, isSymbol: Bool = false, isBackgroundSupressed: Bool = false, preferredColor: CGColor? = nil) {
self.image = image
self.isSymbol = isSymbol
self.preferredColor = preferredColor
self.isBackgroundSupressed = isBackgroundSupressed
}
}

View File

@ -22,11 +22,11 @@ final class FaviconGenerator {
let colorHash = ColorHash(webFeed.url)
if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color.cgColor) {
let iconImage = IconImage(favicon)
let iconImage = IconImage(favicon, isBackgroundSupressed: true)
FaviconGenerator.faviconGeneratorCache[webFeed.url] = iconImage
return iconImage
} else {
return IconImage(AppAssets.faviconTemplateImage)
return IconImage(AppAssets.faviconTemplateImage, isBackgroundSupressed: true)
}
}

View File

@ -154,7 +154,7 @@ struct AppAssets {
}()
static var masterFolderImage: IconImage = {
return IconImage(UIImage(systemName: "folder.fill")!, isSymbol: true)
return IconImage(UIImage(systemName: "folder")!, isSymbol: true, isBackgroundSupressed: true)
}()
static var moreImage: UIImage = {
@ -219,7 +219,7 @@ struct AppAssets {
static var starredFeedImage: IconImage = {
let image = UIImage(named: "smartFeedStar")!
return IconImage(image, isSymbol: true, preferredColor: nil)
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: nil)
}()
static var tickMarkColor: UIColor = {
@ -233,7 +233,7 @@ struct AppAssets {
static var todayFeedImage: IconImage = {
let image = UIImage(named: "smartFeedToday")!
return IconImage(image, isSymbol: true, preferredColor: nil)
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: nil)
}()
static var trashImage: UIImage = {
@ -242,7 +242,7 @@ struct AppAssets {
static var unreadFeedImage: IconImage = {
let image = UIImage(named: "smartFeedUnread")!
return IconImage(image, isSymbol: true, preferredColor: nil)
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: nil)
}()
static var vibrantTextColor: UIColor = {

View File

@ -55,6 +55,10 @@ final class IconView: UIView {
return iconImage?.isSymbol ?? false
}
private var isBackgroundSuppressed: Bool {
return iconImage?.isBackgroundSupressed ?? false
}
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
@ -75,7 +79,7 @@ final class IconView: UIView {
override func layoutSubviews() {
imageView.setFrameIfNotEqual(rectForImageView())
if !isSymbolImage && ((iconImage != nil && isVerticalBackgroundExposed) || !isDisconcernable) {
if !isBackgroundSuppressed && ((iconImage != nil && isVerticalBackgroundExposed) || !isDisconcernable) {
backgroundColor = AppAssets.iconBackgroundColor
} else {
backgroundColor = nil

View File

@ -8,5 +8,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View File

@ -18,5 +18,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View File

@ -18,5 +18,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}