// // TimelineLoaderTableViewCell.swift // Mastodon // // Created by sxiaojian on 2021/2/3. // import UIKit import Combine class TimelineLoaderTableViewCell: UITableViewCell { static let cellHeight: CGFloat = 48 var disposeBag = Set() let loadMoreButton: UIButton = { let button = UIButton(type: .system) button.titleLabel?.font = .preferredFont(forTextStyle: .headline) button.setTitle(L10n.Common.Controls.Timeline.loadMore, for: .normal) return button }() let activityIndicatorView: UIActivityIndicatorView = { let activityIndicatorView = UIActivityIndicatorView(style: .medium) activityIndicatorView.tintColor = .white activityIndicatorView.hidesWhenStopped = true return activityIndicatorView }() override func prepareForReuse() { super.prepareForReuse() disposeBag.removeAll() } override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) _init() } required init?(coder: NSCoder) { super.init(coder: coder) _init() } func _init() { selectionStyle = .none backgroundColor = Asset.Colors.Background.secondarySystemBackground.color loadMoreButton.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(loadMoreButton) NSLayoutConstraint.activate([ loadMoreButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), loadMoreButton.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor), contentView.readableContentGuide.trailingAnchor.constraint(equalTo: loadMoreButton.trailingAnchor), contentView.bottomAnchor.constraint(equalTo: loadMoreButton.bottomAnchor, constant: 8), loadMoreButton.heightAnchor.constraint(equalToConstant: TimelineLoaderTableViewCell.cellHeight - 2 * 8).priority(.defaultHigh), ]) activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false addSubview(activityIndicatorView) NSLayoutConstraint.activate([ activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor), activityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor), ]) loadMoreButton.isHidden = true activityIndicatorView.isHidden = true } }