2019-09-03 04:02:07 +02:00
|
|
|
//
|
2019-10-22 09:35:47 +02:00
|
|
|
// VibrantTableViewCell.swift
|
2019-09-03 04:02:07 +02:00
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Jim Correia on 9/2/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2019-10-22 09:35:47 +02:00
|
|
|
class VibrantTableViewCell: UITableViewCell {
|
2020-10-23 01:56:33 +02:00
|
|
|
|
|
|
|
static let duration: TimeInterval = 0.6
|
|
|
|
|
2019-11-03 01:57:01 +01:00
|
|
|
var labelColor: UIColor {
|
|
|
|
return isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.label
|
|
|
|
}
|
|
|
|
|
2019-11-03 23:34:57 +01:00
|
|
|
var secondaryLabelColor: UIColor {
|
|
|
|
return isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.secondaryLabel
|
|
|
|
}
|
|
|
|
|
2019-09-03 04:02:07 +02:00
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func commonInit() {
|
|
|
|
applyThemeProperties()
|
|
|
|
}
|
2019-11-03 01:57:01 +01:00
|
|
|
|
|
|
|
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
|
|
|
|
super.setHighlighted(highlighted, animated: animated)
|
|
|
|
updateVibrancy(animated: animated)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
updateVibrancy(animated: animated)
|
|
|
|
}
|
2019-09-03 04:02:07 +02:00
|
|
|
|
|
|
|
/// Subclass overrides should call super
|
|
|
|
func applyThemeProperties() {
|
|
|
|
let selectedBackgroundView = UIView(frame: .zero)
|
2019-10-22 10:31:25 +02:00
|
|
|
selectedBackgroundView.backgroundColor = AppAssets.secondaryAccentColor
|
2019-09-03 04:02:07 +02:00
|
|
|
self.selectedBackgroundView = selectedBackgroundView
|
|
|
|
}
|
2019-11-03 01:57:01 +01:00
|
|
|
|
|
|
|
/// Subclass overrides should call super
|
|
|
|
func updateVibrancy(animated: Bool) {
|
2019-11-04 18:47:44 +01:00
|
|
|
updateLabelVibrancy(textLabel, color: labelColor, animated: animated)
|
|
|
|
updateLabelVibrancy(detailTextLabel, color: labelColor, animated: animated)
|
2019-11-03 01:57:01 +01:00
|
|
|
}
|
|
|
|
|
2019-11-04 18:47:44 +01:00
|
|
|
func updateLabelVibrancy(_ label: UILabel?, color: UIColor, animated: Bool) {
|
2019-11-03 01:57:01 +01:00
|
|
|
guard let label = label else { return }
|
2020-10-23 01:56:33 +02:00
|
|
|
if animated {
|
|
|
|
UIView.transition(with: label, duration: Self.duration, options: .transitionCrossDissolve, animations: {
|
|
|
|
label.textColor = color
|
|
|
|
}, completion: nil)
|
|
|
|
} else {
|
2019-11-04 18:47:44 +01:00
|
|
|
label.textColor = color
|
2020-10-23 01:56:33 +02:00
|
|
|
}
|
2019-11-03 01:57:01 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 04:02:07 +02:00
|
|
|
}
|
2020-01-12 22:53:08 +01:00
|
|
|
|
|
|
|
class VibrantBasicTableViewCell: VibrantTableViewCell {
|
|
|
|
|
|
|
|
@IBOutlet private var label: UILabel!
|
2020-03-15 10:25:25 +01:00
|
|
|
@IBOutlet private var detail: UILabel!
|
2020-01-12 22:53:08 +01:00
|
|
|
@IBOutlet private var icon: UIImageView!
|
|
|
|
|
|
|
|
@IBInspectable var imageNormal: UIImage?
|
|
|
|
@IBInspectable var imageSelected: UIImage?
|
|
|
|
|
|
|
|
var iconTint: UIColor {
|
2020-01-13 09:13:02 +01:00
|
|
|
return isHighlighted || isSelected ? labelColor : AppAssets.primaryAccentColor
|
2020-01-12 22:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var iconImage: UIImage? {
|
|
|
|
return isHighlighted || isSelected ? imageSelected : imageNormal
|
|
|
|
}
|
|
|
|
|
|
|
|
override func updateVibrancy(animated: Bool) {
|
|
|
|
super.updateVibrancy(animated: animated)
|
|
|
|
updateIconVibrancy(icon, color: iconTint, image: iconImage, animated: animated)
|
|
|
|
updateLabelVibrancy(label, color: labelColor, animated: animated)
|
2020-03-15 10:25:25 +01:00
|
|
|
updateLabelVibrancy(detail, color: secondaryLabelColor, animated: animated)
|
2020-01-12 22:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private func updateIconVibrancy(_ icon: UIImageView?, color: UIColor, image: UIImage?, animated: Bool) {
|
|
|
|
guard let icon = icon else { return }
|
2020-10-23 01:56:33 +02:00
|
|
|
if animated {
|
|
|
|
UIView.transition(with: icon, duration: Self.duration, options: .transitionCrossDissolve, animations: {
|
|
|
|
icon.tintColor = color
|
|
|
|
icon.image = image
|
|
|
|
}, completion: nil)
|
|
|
|
} else {
|
2020-01-12 22:53:08 +01:00
|
|
|
icon.tintColor = color
|
|
|
|
icon.image = image
|
2020-10-23 01:56:33 +02:00
|
|
|
}
|
2020-01-12 22:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|