commit
709e89cbfb
@ -1,76 +1,78 @@ |
||||
// Copyright © 2020 Stormbird PTE. LTD. |
||||
|
||||
import UIKit |
||||
extension AddHideTokensViewController { |
||||
class functional {} |
||||
} |
||||
|
||||
class AddHideTokenSectionHeaderView: UITableViewHeaderFooterView { |
||||
private lazy var titleLabel: UILabel = { |
||||
let label = UILabel() |
||||
label.translatesAutoresizingMaskIntoConstraints = false |
||||
label.font = Fonts.bold(size: 24) |
||||
label.textColor = .black |
||||
extension AddHideTokensViewController.functional { |
||||
|
||||
return label |
||||
}() |
||||
static func headerView(for section: Int, viewModel: AddHideTokenSectionHeaderViewModel) -> UIView { |
||||
let view = AddHideTokenSectionHeaderView() |
||||
view.configure(viewModel: viewModel) |
||||
|
||||
var rightAccessoryView: UIView? { |
||||
didSet { |
||||
if let view = rightAccessoryView { |
||||
setup(rightAccessoryView: view) |
||||
} else if let oldValue = oldValue { |
||||
oldValue.removeFromSuperview() |
||||
} |
||||
return view |
||||
} |
||||
} |
||||
|
||||
private var separatorView: UIView = { |
||||
private class AddHideTokenSectionHeaderView: UIView { |
||||
|
||||
private let titleLabel: UILabel = { |
||||
let label = UILabel() |
||||
label.translatesAutoresizingMaskIntoConstraints = false |
||||
return label |
||||
}() |
||||
|
||||
private let topSeparator: UIView = { |
||||
let view = UIView() |
||||
view.translatesAutoresizingMaskIntoConstraints = false |
||||
|
||||
view.backgroundColor = R.color.mercury() |
||||
return view |
||||
}() |
||||
|
||||
override init(reuseIdentifier: String?) { |
||||
super.init(reuseIdentifier: reuseIdentifier) |
||||
setupViews() |
||||
} |
||||
|
||||
required init?(coder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
private let bottomSperator: UIView = { |
||||
let view = UIView() |
||||
view.translatesAutoresizingMaskIntoConstraints = false |
||||
view.backgroundColor = R.color.mercury() |
||||
return view |
||||
}() |
||||
|
||||
override func awakeFromNib() { |
||||
super.awakeFromNib() |
||||
private var topSeparatorHeight: NSLayoutConstraint! |
||||
|
||||
setupViews() |
||||
} |
||||
init() { |
||||
super.init(frame: .zero) |
||||
|
||||
private func setupViews() { |
||||
backgroundColor = .white |
||||
contentView.backgroundColor = .white |
||||
addSubview(titleLabel) |
||||
addSubview(separatorView) |
||||
let stackView = [ |
||||
topSeparator, |
||||
.spacer(height: 20, backgroundColor: .clear), |
||||
[.spacerWidth(16), titleLabel, .spacerWidth(16)].asStackView(axis: .horizontal), |
||||
.spacer(height: 20, backgroundColor: .clear), |
||||
bottomSperator |
||||
].asStackView(axis: .vertical) |
||||
stackView.translatesAutoresizingMaskIntoConstraints = false |
||||
addSubview(stackView) |
||||
|
||||
NSLayoutConstraint.activate([ |
||||
titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor), |
||||
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), |
||||
separatorView.centerXAnchor.constraint(equalTo: centerXAnchor), |
||||
separatorView.widthAnchor.constraint(equalTo: widthAnchor), |
||||
separatorView.heightAnchor.constraint(equalToConstant: GroupedTable.Metric.cellSeparatorHeight), |
||||
separatorView.bottomAnchor.constraint(equalTo: bottomAnchor) |
||||
stackView.anchorsConstraint(to: self), |
||||
bottomSperator.heightAnchor.constraint(equalToConstant: 1) |
||||
]) |
||||
} |
||||
|
||||
private func setup(rightAccessoryView: UIView) { |
||||
addSubview(rightAccessoryView) |
||||
topSeparatorHeight = topSeparator.heightAnchor.constraint(equalToConstant: 1) |
||||
topSeparatorHeight.isActive = true |
||||
} |
||||
|
||||
NSLayoutConstraint.activate([ |
||||
rightAccessoryView.widthAnchor.constraint(equalTo: widthAnchor), |
||||
rightAccessoryView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16) |
||||
]) |
||||
required init?(coder aDecoder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
|
||||
func configure(viewModel: AddHideTokenSectionHeaderViewModel) { |
||||
titleLabel.text = viewModel.text |
||||
separatorView.backgroundColor = viewModel.separatorColor |
||||
titleLabel.text = viewModel.titleText |
||||
titleLabel.textColor = viewModel.titleTextColor |
||||
titleLabel.font = viewModel.titleTextFont |
||||
|
||||
topSeparator.backgroundColor = viewModel.separatorColor |
||||
bottomSperator.backgroundColor = viewModel.separatorColor |
||||
backgroundColor = viewModel.backgroundColor |
||||
topSeparatorHeight.constant = viewModel.showTopSeparator ? 1 : 0 |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue