Improve artwork collection view compatibility with older macOS versions.
This commit is contained in:
5 files changed
+42
-21
No files matched your search
@@ -130,6 +130,7 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
}
|
||||
|
||||
private func setUp() {
|
||||
layer = CALayer()
|
||||
wantsLayer = true
|
||||
|
||||
imageLayer.anchorPoint = CGPoint.zero
|
||||
@@ -143,6 +144,7 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
|
||||
backgroundLayer.anchorPoint = CGPoint.zero
|
||||
backgroundLayer.position = CGPoint(x: 0, y: 36)
|
||||
backgroundLayer.backgroundColor = NSColor.controlHighlightColor.cgColor
|
||||
backgroundLayer.cornerRadius = 8
|
||||
backgroundLayer.isHidden = true
|
||||
backgroundLayer.isOpaque = true
|
||||
@@ -162,6 +164,8 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
backgroundLayer.actions = actions
|
||||
emptyLayer.actions = actions
|
||||
|
||||
updateBackgroundColor()
|
||||
|
||||
layer?.addSublayer(backgroundLayer)
|
||||
layer?.addSublayer(emptyLayer)
|
||||
layer?.addSublayer(imageLayer)
|
||||
@@ -183,21 +187,24 @@ final class ArtworkSelectorViewItemView: NSView {
|
||||
}
|
||||
}
|
||||
|
||||
override var wantsUpdateLayer: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override func updateLayer() {
|
||||
private func updateBackgroundColor() {
|
||||
if #available(OSX 10.14, *) {
|
||||
let saved = NSAppearance.current
|
||||
NSAppearance.current = effectiveAppearance
|
||||
|
||||
imageLayer.shadowColor = NSColor.labelColor.cgColor
|
||||
backgroundLayer.backgroundColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||
emptyLayer.strokeColor = NSColor.secondarySelectedControlColor.cgColor
|
||||
emptyLayer.fillColor = NSColor.windowBackgroundColor.cgColor
|
||||
} else {
|
||||
backgroundLayer.backgroundColor = NSColor.controlHighlightColor.cgColor
|
||||
|
||||
NSAppearance.current = saved
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidChangeEffectiveAppearance() {
|
||||
updateBackgroundColor()
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
super.layout()
|
||||
imageLayer.bounds = CGRect(x: 0, y: 0, width: bounds.width - 8, height: bounds.height - 44)
|
||||
|
||||
Reference in new issue
Block a user