mastodon-ios/Mastodon/Scene/Share/View/TableviewCell/TimelineLoaderTableViewCell...

99 lines
3.5 KiB
Swift
Raw Normal View History

2021-02-03 06:01:50 +01:00
//
// TimelineLoaderTableViewCell.swift
// Mastodon
//
// Created by sxiaojian on 2021/2/3.
//
import UIKit
import Combine
class TimelineLoaderTableViewCell: UITableViewCell {
static let buttonHeight: CGFloat = 62
static let cellHeight: CGFloat = TimelineLoaderTableViewCell.buttonHeight + 17
static let extraTopPadding: CGFloat = 10
2021-02-03 06:01:50 +01:00
var disposeBag = Set<AnyCancellable>()
var stateBindDispose: AnyCancellable?
2021-02-03 06:01:50 +01:00
let loadMoreButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = Asset.Colors.lightWhite.color
2021-02-03 06:01:50 +01:00
return button
}()
private let loadMoreLabel: UILabel = {
let label = UILabel()
label.font = .preferredFont(forTextStyle: .body)
return label
}()
private let activityIndicatorView: UIActivityIndicatorView = {
2021-02-03 06:01:50 +01:00
let activityIndicatorView = UIActivityIndicatorView(style: .medium)
activityIndicatorView.tintColor = Asset.Colors.lightSecondaryText.color
2021-02-03 06:01:50 +01:00
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 startAnimating() {
activityIndicatorView.startAnimating()
self.loadMoreLabel.textColor = Asset.Colors.lightSecondaryText.color
self.loadMoreLabel.text = L10n.Common.Controls.Timeline.Loader.loadingMissingPosts
}
func stopAnimating() {
activityIndicatorView.stopAnimating()
self.loadMoreLabel.textColor = Asset.Colors.buttonDefault.color
self.loadMoreLabel.text = L10n.Common.Controls.Timeline.Loader.loadMissingPosts
}
2021-02-03 06:01:50 +01:00
func _init() {
selectionStyle = .none
backgroundColor = Asset.Colors.Background.secondarySystemBackground.color
2021-02-03 06:01:50 +01:00
loadMoreButton.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(loadMoreButton)
NSLayoutConstraint.activate([
loadMoreButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 7),
loadMoreButton.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
contentView.trailingAnchor.constraint(equalTo: loadMoreButton.trailingAnchor),
contentView.bottomAnchor.constraint(equalTo: loadMoreButton.bottomAnchor, constant: 14),
loadMoreButton.heightAnchor.constraint(equalToConstant: TimelineLoaderTableViewCell.buttonHeight).priority(.defaultHigh),
])
loadMoreLabel.translatesAutoresizingMaskIntoConstraints = false
addSubview(loadMoreLabel)
NSLayoutConstraint.activate([
loadMoreLabel.centerXAnchor.constraint(equalTo: loadMoreButton.centerXAnchor),
loadMoreLabel.centerYAnchor.constraint(equalTo: loadMoreButton.centerYAnchor),
2021-02-03 06:01:50 +01:00
])
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
addSubview(activityIndicatorView)
NSLayoutConstraint.activate([
activityIndicatorView.centerYAnchor.constraint(equalTo: loadMoreButton.centerYAnchor),
activityIndicatorView.trailingAnchor.constraint(equalTo: loadMoreLabel.leadingAnchor),
2021-02-03 06:01:50 +01:00
])
activityIndicatorView.isHidden = true
}
}