mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Rename MasterTimelineAvatarView to AvatarView
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// MasterTimelineAvatarView.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 9/17/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
final class MasterTimelineAvatarView: UIView {
|
||||
|
||||
var image: UIImage? = nil {
|
||||
didSet {
|
||||
if image !== oldValue {
|
||||
imageView.image = image
|
||||
|
||||
if self.traitCollection.userInterfaceStyle == .dark {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
if self.image?.isDark() ?? false {
|
||||
DispatchQueue.main.async {
|
||||
self.isDisconcernable = false
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
self.isDisconcernable = true
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var isDisconcernable = true
|
||||
|
||||
private let imageView: UIImageView = {
|
||||
let imageView = NonIntrinsicImageView(image: AppAssets.faviconTemplateImage)
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
imageView.clipsToBounds = true
|
||||
imageView.layer.cornerRadius = 2.0
|
||||
return imageView
|
||||
}()
|
||||
|
||||
private var isVerticalBackgroundExposed: Bool {
|
||||
return imageView.frame.size.height < bounds.size.height
|
||||
}
|
||||
|
||||
private var isSymbolImage: Bool {
|
||||
return imageView.image?.isSymbolImage ?? false
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
convenience init() {
|
||||
self.init(frame: .zero)
|
||||
}
|
||||
|
||||
override func didMoveToSuperview() {
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
imageView.setFrameIfNotEqual(rectForImageView())
|
||||
if (isVerticalBackgroundExposed && !isSymbolImage) || !isDisconcernable {
|
||||
backgroundColor = AppAssets.avatarBackgroundColor
|
||||
} else {
|
||||
backgroundColor = nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension MasterTimelineAvatarView {
|
||||
|
||||
func commonInit() {
|
||||
layer.cornerRadius = MasterTimelineDefaultCellLayout.avatarCornerRadius
|
||||
clipsToBounds = true
|
||||
addSubview(imageView)
|
||||
}
|
||||
|
||||
func rectForImageView() -> CGRect {
|
||||
guard let image = image else {
|
||||
return CGRect.zero
|
||||
}
|
||||
|
||||
let imageSize = image.size
|
||||
let viewSize = bounds.size
|
||||
if imageSize.height == imageSize.width {
|
||||
if imageSize.height >= viewSize.height * 0.75 {
|
||||
// Close enough to viewSize to scale up the image.
|
||||
return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height)
|
||||
}
|
||||
let offset = floor((viewSize.height - imageSize.height) / 2.0)
|
||||
return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height)
|
||||
}
|
||||
else if imageSize.height > imageSize.width {
|
||||
let factor = viewSize.height / imageSize.height
|
||||
let width = imageSize.width * factor
|
||||
let originX = floor((viewSize.width - width) / 2.0)
|
||||
return CGRect(x: originX, y: 0.0, width: width, height: viewSize.height)
|
||||
}
|
||||
|
||||
// Wider than tall: imageSize.width > imageSize.height
|
||||
let factor = viewSize.width / imageSize.width
|
||||
let height = imageSize.height * factor
|
||||
let originY = floor((viewSize.height - height) / 2.0)
|
||||
return CGRect(x: 0.0, y: originY, width: viewSize.width, height: height)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ class MasterTimelineTableViewCell: VibrantTableViewCell {
|
||||
private let dateView = MasterTimelineTableViewCell.singleLineUILabel()
|
||||
private let feedNameView = MasterTimelineTableViewCell.singleLineUILabel()
|
||||
|
||||
private lazy var avatarView = MasterTimelineAvatarView()
|
||||
private lazy var avatarView = AvatarView()
|
||||
|
||||
private lazy var starView = {
|
||||
return NonIntrinsicImageView(image: AppAssets.timelineStarImage)
|
||||
|
||||
@@ -10,7 +10,7 @@ import UIKit
|
||||
|
||||
class MasterTimelineTitleView: UIView {
|
||||
|
||||
@IBOutlet weak var avatarView: MasterTimelineAvatarView!
|
||||
@IBOutlet weak var avatarView: AvatarView!
|
||||
@IBOutlet weak var label: UILabel!
|
||||
@IBOutlet weak var unreadCountView: MasterTimelineUnreadCountView!
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<rect key="frame" x="79.5" y="9" width="110.5" height="20"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5gI-Wl-lnK" customClass="MasterTimelineAvatarView" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5gI-Wl-lnK" customClass="AvatarView" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="9" width="20" height="20"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
|
||||
Reference in New Issue
Block a user