From 5643a51d16f6882c6970283e00002b50d0cb5286 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 23 Feb 2018 23:31:59 -0800 Subject: [PATCH] =?UTF-8?q?Skip=20showing=20favicons=20in=20the=20timeline?= =?UTF-8?q?=20when=20they=E2=80=99re=20too=20small=20to=20look=20good.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Timeline/Cell/TimelineTableCellView.swift | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift b/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift index 335e2301f..4d0927a74 100644 --- a/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift +++ b/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift @@ -17,7 +17,13 @@ class TimelineTableCellView: NSTableCellView { private let unreadIndicatorView = UnreadIndicatorView(frame: NSZeroRect) private let dateView = TimelineTableCellView.singleLineTextField() private let feedNameView = TimelineTableCellView.singleLineTextField() - private let avatarImageView = TimelineTableCellView.imageView(with: AppImages.genericFeedImage, scaling: .scaleProportionallyDown) + + private lazy var avatarImageView: NSImageView = { + let imageView = TimelineTableCellView.imageView(with: AppImages.genericFeedImage, scaling: .scaleProportionallyDown) + imageView.wantsLayer = true + return imageView + }() + private let starView = TimelineTableCellView.imageView(with: AppImages.timelineStar, scaling: .scaleNone) private lazy var textFields = { @@ -27,6 +33,7 @@ class TimelineTableCellView: NSTableCellView { var cellAppearance: TimelineCellAppearance! { didSet { updateTextFields() + avatarImageView.layer?.cornerRadius = cellAppearance.avatarCornerRadius needsLayout = true } } @@ -297,25 +304,26 @@ private extension TimelineTableCellView { func updateAvatar() { - if !cellData.showAvatar { - avatarImageView.image = nil - hideView(avatarImageView) + // The avatar should be bigger than a favicon. They’re too small; they look weird. + guard let image = cellData.avatar, cellData.showAvatar, image.size.height >= 22.0, image.size.width >= 22.0 else { + makeAvatarEmpty() return } showView(avatarImageView) - - if let image = cellData.avatar { - if avatarImageView.image !== image { - avatarImageView.image = image - } + if avatarImageView.image !== image { + avatarImageView.image = image + needsLayout = true } - else { + } + + func makeAvatarEmpty() { + + if avatarImageView.image != nil { avatarImageView.image = nil + needsLayout = true } - - avatarImageView.wantsLayer = true - avatarImageView.layer?.cornerRadius = cellAppearance.avatarCornerRadius + hideView(avatarImageView) } func hideView(_ view: NSView) {