|
|
|
@ -4,18 +4,86 @@ import Foundation |
|
|
|
|
import UIKit |
|
|
|
|
import Kingfisher |
|
|
|
|
|
|
|
|
|
struct ApprecationViewModel { |
|
|
|
|
let valueAttributedString: NSAttributedString |
|
|
|
|
let icon: UIImage? |
|
|
|
|
let backgroundColor: UIColor |
|
|
|
|
|
|
|
|
|
init(icon: UIImage?, valueAttributedString: NSAttributedString, backgroundColor: UIColor) { |
|
|
|
|
self.valueAttributedString = valueAttributedString |
|
|
|
|
self.icon = icon |
|
|
|
|
self.backgroundColor = backgroundColor |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class ApprecationView: UIView { |
|
|
|
|
|
|
|
|
|
private let valueLabel: UILabel = { |
|
|
|
|
let view = UILabel() |
|
|
|
|
view.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
view.textAlignment = .center |
|
|
|
|
view.setContentCompressionResistancePriority(.required, for: .vertical) |
|
|
|
|
view.setContentHuggingPriority(.required, for: .vertical) |
|
|
|
|
|
|
|
|
|
return view |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
private let iconView: UIImageView = { |
|
|
|
|
let view = UIImageView() |
|
|
|
|
view.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
view.contentMode = .scaleAspectFit |
|
|
|
|
return view |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
init(edgeInsets: UIEdgeInsets = .init(top: 0, left: 2, bottom: 0, right: 2), spacing: CGFloat = 4) { |
|
|
|
|
super.init(frame: .zero) |
|
|
|
|
self.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
|
|
let stackView = [iconView, valueLabel].asStackView(spacing: spacing, alignment: .center) |
|
|
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
|
|
addSubview(stackView) |
|
|
|
|
setContentCompressionResistancePriority(.required, for: .vertical) |
|
|
|
|
setContentHuggingPriority(.required, for: .vertical) |
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([ |
|
|
|
|
iconView.widthAnchor.constraint(equalToConstant: 9), |
|
|
|
|
iconView.heightAnchor.constraint(equalToConstant: 9), |
|
|
|
|
|
|
|
|
|
stackView.anchorsConstraint(to: self, edgeInsets: edgeInsets) |
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func configure(viewModel: ApprecationViewModel) { |
|
|
|
|
valueLabel.attributedText = viewModel.valueAttributedString |
|
|
|
|
iconView.image = viewModel.icon |
|
|
|
|
iconView.isHidden = viewModel.icon == nil |
|
|
|
|
backgroundColor = viewModel.backgroundColor |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override func layoutSubviews() { |
|
|
|
|
super.layoutSubviews() |
|
|
|
|
|
|
|
|
|
layer.cornerRadius = 2.0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class EthTokenViewCell: UITableViewCell { |
|
|
|
|
private let background = UIView() |
|
|
|
|
private let titleLabel = UILabel() |
|
|
|
|
private let apprecation24hoursLabel = UILabel() |
|
|
|
|
private let apprecation24hoursView = ApprecationView() |
|
|
|
|
private let priceChangeLabel = UILabel() |
|
|
|
|
private let fiatValueLabel = UILabel() |
|
|
|
|
private let cryptoValueLabel = UILabel() |
|
|
|
|
private var viewsWithContent: [UIView] { |
|
|
|
|
[titleLabel, apprecation24hoursLabel, priceChangeLabel] |
|
|
|
|
[titleLabel, apprecation24hoursView, priceChangeLabel] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private lazy var changeValueContainer: UIView = [priceChangeLabel, apprecation24hoursLabel].asStackView(spacing: 5) |
|
|
|
|
private lazy var changeValueContainer: UIView = [priceChangeLabel, apprecation24hoursView].asStackView(spacing: 5) |
|
|
|
|
|
|
|
|
|
private var tokenIconImageView: TokenImageView = { |
|
|
|
|
let imageView = TokenImageView() |
|
|
|
@ -30,17 +98,17 @@ class EthTokenViewCell: UITableViewCell { |
|
|
|
|
|
|
|
|
|
contentView.addSubview(background) |
|
|
|
|
background.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
apprecation24hoursLabel.textAlignment = .center |
|
|
|
|
priceChangeLabel.textAlignment = .center |
|
|
|
|
fiatValueLabel.textAlignment = .center |
|
|
|
|
fiatValueLabel.setContentCompressionResistancePriority(.required, for: .horizontal) |
|
|
|
|
fiatValueLabel.setContentHuggingPriority(.required, for: .horizontal) |
|
|
|
|
|
|
|
|
|
let col0 = tokenIconImageView |
|
|
|
|
let row1 = [cryptoValueLabel, UIView.spacerWidth(flexible: true), changeValueContainer, blockChainTagLabel].asStackView(spacing: 5, alignment: .center) |
|
|
|
|
let col1 = [ |
|
|
|
|
[titleLabel, UIView.spacerWidth(flexible: true), fiatValueLabel].asStackView(spacing: 5), |
|
|
|
|
[cryptoValueLabel, UIView.spacerWidth(flexible: true), changeValueContainer, blockChainTagLabel].asStackView(spacing: 5) |
|
|
|
|
].asStackView(axis: .vertical, spacing: 2) |
|
|
|
|
row1 |
|
|
|
|
].asStackView(axis: .vertical) |
|
|
|
|
let stackView = [col0, col1].asStackView(spacing: 12, alignment: .center) |
|
|
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
background.addSubview(stackView) |
|
|
|
@ -48,7 +116,8 @@ class EthTokenViewCell: UITableViewCell { |
|
|
|
|
NSLayoutConstraint.activate([ |
|
|
|
|
tokenIconImageView.heightAnchor.constraint(equalToConstant: 40), |
|
|
|
|
tokenIconImageView.widthAnchor.constraint(equalToConstant: 40), |
|
|
|
|
stackView.anchorsConstraint(to: background, edgeInsets: .init(top: 16, left: 20, bottom: 16, right: 16)), |
|
|
|
|
row1.heightAnchor.constraint(greaterThanOrEqualToConstant: 20), |
|
|
|
|
stackView.anchorsConstraint(to: background, edgeInsets: .init(top: 12, left: 20, bottom: 16, right: 12)), |
|
|
|
|
background.anchorsConstraint(to: contentView) |
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
@ -70,10 +139,9 @@ class EthTokenViewCell: UITableViewCell { |
|
|
|
|
cryptoValueLabel.attributedText = viewModel.cryptoValueAttributedString |
|
|
|
|
cryptoValueLabel.baselineAdjustment = .alignCenters |
|
|
|
|
|
|
|
|
|
apprecation24hoursLabel.attributedText = viewModel.apprecation24hoursAttributedString |
|
|
|
|
apprecation24hoursLabel.backgroundColor = viewModel.apprecation24hoursBackgroundColor |
|
|
|
|
apprecation24hoursView.configure(viewModel: viewModel.apprecationViewModel) |
|
|
|
|
|
|
|
|
|
priceChangeLabel.attributedText = viewModel.priceChangeUSDAttributedString |
|
|
|
|
priceChangeLabel.attributedText = viewModel.priceChangeUSDValueAttributedString |
|
|
|
|
|
|
|
|
|
fiatValueLabel.attributedText = viewModel.fiatValueAttributedString |
|
|
|
|
|
|
|
|
@ -85,10 +153,4 @@ class EthTokenViewCell: UITableViewCell { |
|
|
|
|
blockChainTagLabel.configure(viewModel: viewModel.blockChainTagViewModel) |
|
|
|
|
changeValueContainer.isHidden = !viewModel.blockChainTagViewModel.blockChainNameLabelHidden |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override func layoutSubviews() { |
|
|
|
|
super.layoutSubviews() |
|
|
|
|
|
|
|
|
|
priceChangeLabel.layer.cornerRadius = 2.0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|