mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 08:17:16 +00:00
Show background color before image loads (when the view is a placeholder). Give a corner radius to large thumbnails.
This commit is contained in:
1 parent
eac971b275
commit
cd6dd9ab29
5 files changed
+37
-20
No files matched your search
@@ -59,9 +59,6 @@ final class IconView: NSView {
|
||||
return imageView.frame.size.height < bounds.size.height
|
||||
}
|
||||
|
||||
private static var lightBackgroundColor = Assets.Colors.iconLightBackground
|
||||
private static var darkBackgroundColor = Assets.Colors.iconDarkBackground
|
||||
|
||||
override init(frame frameRect: NSRect) {
|
||||
super.init(frame: frameRect)
|
||||
commonInit()
|
||||
@@ -93,9 +90,9 @@ final class IconView: NSView {
|
||||
guard !(iconImage?.isBackgroundSuppressed ?? false) else { return }
|
||||
guard hasExposedVerticalBackground || !isDiscernable else { return }
|
||||
|
||||
let color = NSApplication.shared.effectiveAppearance.isDarkMode ? IconView.darkBackgroundColor : IconView.lightBackgroundColor
|
||||
color.set()
|
||||
dirtyRect.fill()
|
||||
// The fill is translucent, so it’s blended, not copied.
|
||||
Assets.Colors.iconBackground.set()
|
||||
dirtyRect.fill(using: .sourceOver)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import AppKit
|
||||
|
||||
/// An article’s thumbnail in a timeline cell.
|
||||
///
|
||||
/// The whole image shows, scaled to fit, on a fill that is also the placeholder until the image arrives.
|
||||
/// The whole image shows, scaled to fit. The cell sizes the view to the image, so the corner radius rounds the image itself.
|
||||
/// A placeholder color shows until the image arrives.
|
||||
final class ThumbnailView: NSView {
|
||||
|
||||
var image: NSImage? {
|
||||
@@ -50,6 +51,8 @@ final class ThumbnailView: NSView {
|
||||
|
||||
override func updateLayer() {
|
||||
layer?.contents = image?.cgImage(forProposedRect: nil, context: nil, hints: nil)
|
||||
// Resolved here so the placeholder follows light and dark mode.
|
||||
layer?.backgroundColor = image == nil ? Assets.Colors.thumbnailPlaceholder.cgColor : nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
thumbnailView.image
|
||||
}
|
||||
set {
|
||||
thumbnailView.image = newValue
|
||||
setThumbnailImage(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ final class TimelineTableCellView: NSTableCellView {
|
||||
unreadIndicatorView.setFrameIfNotEqual(layoutRects.unreadIndicatorRect)
|
||||
feedNameView.setFrameIfNotEqual(layoutRects.feedNameRect)
|
||||
iconView.setFrameIfNotEqual(layoutRects.iconImageRect)
|
||||
thumbnailView.setFrameIfNotEqual(layoutRects.thumbnailRect)
|
||||
// Sized to the image, so the corner radius rounds the image itself. All of the rect until the image arrives.
|
||||
thumbnailView.setFrameIfNotEqual(layoutRects.thumbnailRect.aspectFitRect(for: thumbnailView.image?.size ?? .zero))
|
||||
starView.setFrameIfNotEqual(layoutRects.starRect)
|
||||
}
|
||||
}
|
||||
@@ -306,7 +307,7 @@ private extension TimelineTableCellView {
|
||||
showView(thumbnailView)
|
||||
needsLayout = true
|
||||
}
|
||||
thumbnailView.image = cellData.thumbnail
|
||||
setThumbnailImage(cellData.thumbnail)
|
||||
}
|
||||
|
||||
func makeThumbnailEmpty() {
|
||||
@@ -314,7 +315,15 @@ private extension TimelineTableCellView {
|
||||
hideView(thumbnailView)
|
||||
needsLayout = true
|
||||
}
|
||||
thumbnailView.image = nil
|
||||
setThumbnailImage(nil)
|
||||
}
|
||||
|
||||
/// Lays out again, since the thumbnail view is sized to the image.
|
||||
func setThumbnailImage(_ image: NSImage?) {
|
||||
if thumbnailView.image !== image {
|
||||
thumbnailView.image = image
|
||||
needsLayout = true
|
||||
}
|
||||
}
|
||||
|
||||
func hideView(_ view: NSView) {
|
||||
|
||||
@@ -65,8 +65,7 @@ struct IconImageView: View {
|
||||
|
||||
private var backgroundColor: Color {
|
||||
#if os(macOS)
|
||||
let nsColor = isDarkMode ? Assets.Colors.iconDarkBackground : Assets.Colors.iconLightBackground
|
||||
return Color(nsColor: nsColor)
|
||||
return Color(nsColor: Assets.Colors.iconBackground)
|
||||
#else
|
||||
return Color(Assets.Colors.iconBackground)
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,7 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
thumbnailView.image
|
||||
}
|
||||
set {
|
||||
thumbnailView.image = newValue
|
||||
setThumbnailImage(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
indicatorView.isHidden = true
|
||||
thumbnailView.image = nil
|
||||
setThumbnailImage(nil)
|
||||
}
|
||||
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
@@ -77,7 +77,8 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
feedNameView.setFrameIfNotEqual(layout.feedNameRect)
|
||||
dateView.setFrameIfNotEqual(layout.dateRect)
|
||||
iconView.setFrameIfNotEqual(layout.iconImageRect)
|
||||
thumbnailView.setFrameIfNotEqual(layout.thumbnailRect)
|
||||
// Sized to the image, so the corner radius rounds the image itself. All of the rect until the image arrives.
|
||||
thumbnailView.setFrameIfNotEqual(layout.thumbnailRect.aspectFitRect(for: thumbnailView.image?.size ?? .zero))
|
||||
indicatorView.setFrameIfNotEqual(cellData.starred ? layout.starRect : layout.unreadIndicatorRect)
|
||||
topSeparator.frame = CGRect(x: layout.separatorRect.minX, y: 0, width: layout.separatorRect.width, height: 1.0 / traitCollection.displayScale)
|
||||
}
|
||||
@@ -165,6 +166,7 @@ private extension MainTimelineCell {
|
||||
thumbnailView.contentMode = .scaleAspectFit
|
||||
thumbnailView.clipsToBounds = true
|
||||
thumbnailView.layer.cornerRadius = MainTimelineDefaultCellLayout.thumbnailCornerRadius
|
||||
thumbnailView.backgroundColor = Assets.Colors.thumbnailPlaceholder
|
||||
for view in [titleView, summaryView, dateView, feedNameView, iconView, indicatorView, thumbnailView, topSeparator] {
|
||||
contentView.addSubview(view)
|
||||
view.isAccessibilityElement = false
|
||||
@@ -183,6 +185,15 @@ private extension MainTimelineCell {
|
||||
return MainTimelineDefaultCellLayout(width: width, insets: .zero, cellData: cellData)
|
||||
}
|
||||
|
||||
/// Lays out again, since the thumbnail view is sized to the image. The placeholder color shows until there’s an image.
|
||||
func setThumbnailImage(_ image: UIImage?) {
|
||||
if thumbnailView.image !== image {
|
||||
thumbnailView.image = image
|
||||
thumbnailView.backgroundColor = image == nil ? Assets.Colors.thumbnailPlaceholder : nil
|
||||
setNeedsLayout()
|
||||
}
|
||||
}
|
||||
|
||||
func setFrame(for label: UILabel, rect: CGRect) {
|
||||
if Int(floor(rect.height)) == 0 || Int(floor(rect.width)) == 0 {
|
||||
label.isHidden = true
|
||||
@@ -224,12 +235,10 @@ private extension MainTimelineCell {
|
||||
}
|
||||
|
||||
if cellData.showThumbnail {
|
||||
thumbnailView.image = cellData.thumbnail
|
||||
// Matches the Mac. The fill shows around the image, and in place of it until it arrives.
|
||||
thumbnailView.backgroundColor = cellData.thumbnailsDisplay == .large ? .tertiarySystemFill : .systemFill
|
||||
setThumbnailImage(cellData.thumbnail)
|
||||
thumbnailView.isHidden = false
|
||||
} else {
|
||||
thumbnailView.image = nil
|
||||
setThumbnailImage(nil)
|
||||
thumbnailView.isHidden = true
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user