mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Simplify iconImage:didSet. Move background color update to a private helper function.
This commit is contained in:
parent
954a676cbe
commit
1d4ef582a7
@ -12,33 +12,24 @@ final class IconView: UIView {
|
||||
|
||||
var iconImage: IconImage? = nil {
|
||||
didSet {
|
||||
if iconImage !== oldValue {
|
||||
imageView.image = iconImage?.image
|
||||
|
||||
if self.traitCollection.userInterfaceStyle == .dark {
|
||||
if self.iconImage?.isDark ?? false {
|
||||
self.isDiscernable = false
|
||||
self.setNeedsLayout()
|
||||
} else {
|
||||
self.isDiscernable = true
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
} else {
|
||||
if self.iconImage?.isBright ?? false {
|
||||
self.isDiscernable = false
|
||||
self.setNeedsLayout()
|
||||
} else {
|
||||
self.isDiscernable = true
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
self.setNeedsLayout()
|
||||
guard iconImage !== oldValue else {
|
||||
return
|
||||
}
|
||||
imageView.image = iconImage?.image
|
||||
if traitCollection.userInterfaceStyle == .dark {
|
||||
let isDark = iconImage?.isDark ?? false
|
||||
isDiscernable = !isDark
|
||||
}
|
||||
else {
|
||||
let isBright = iconImage?.isBright ?? false
|
||||
isDiscernable = !isBright
|
||||
}
|
||||
setNeedsLayout()
|
||||
}
|
||||
}
|
||||
|
||||
private var isDiscernable = true
|
||||
|
||||
|
||||
private let imageView: UIImageView = {
|
||||
let imageView = NonIntrinsicImageView(image: AppAssets.faviconTemplateImage)
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
@ -79,13 +70,8 @@ final class IconView: UIView {
|
||||
|
||||
override func layoutSubviews() {
|
||||
imageView.setFrameIfNotEqual(rectForImageView())
|
||||
if !isBackgroundSuppressed && ((iconImage != nil && isVerticalBackgroundExposed) || !isDiscernable) {
|
||||
backgroundColor = AppAssets.iconBackgroundColor
|
||||
} else {
|
||||
backgroundColor = nil
|
||||
}
|
||||
updateBackgroundColor()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension IconView {
|
||||
@ -125,4 +111,11 @@ private extension IconView {
|
||||
return CGRect(x: 0.0, y: originY, width: viewSize.width, height: height)
|
||||
}
|
||||
|
||||
private func updateBackgroundColor() {
|
||||
if !isBackgroundSuppressed && ((iconImage != nil && isVerticalBackgroundExposed) || !isDiscernable) {
|
||||
backgroundColor = AppAssets.iconBackgroundColor
|
||||
} else {
|
||||
backgroundColor = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user