2021-02-04 08:09:58 +01:00
|
|
|
//
|
|
|
|
// TimelineMiddleLoaderTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/4.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
|
2021-05-08 05:03:34 +02:00
|
|
|
protocol TimelineMiddleLoaderTableViewCellDelegate: AnyObject {
|
2021-02-04 08:09:58 +01:00
|
|
|
func timelineMiddleLoaderTableViewCell(_ cell: TimelineMiddleLoaderTableViewCell, loadMoreButtonDidPressed button: UIButton)
|
|
|
|
}
|
|
|
|
|
|
|
|
final class TimelineMiddleLoaderTableViewCell: TimelineLoaderTableViewCell {
|
2022-01-27 14:23:39 +01:00
|
|
|
|
2021-02-04 08:09:58 +01:00
|
|
|
weak var delegate: TimelineMiddleLoaderTableViewCellDelegate?
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
private(set) lazy var viewModel: ViewModel = {
|
|
|
|
let viewModel = ViewModel()
|
|
|
|
viewModel.bind(cell: self)
|
|
|
|
return viewModel
|
|
|
|
}()
|
|
|
|
|
2021-04-13 13:46:42 +02:00
|
|
|
let topSawToothView = SawToothView()
|
|
|
|
let bottomSawToothView = SawToothView()
|
2021-03-17 05:17:48 +01:00
|
|
|
|
2021-02-04 08:09:58 +01:00
|
|
|
override func _init() {
|
|
|
|
super._init()
|
|
|
|
|
2021-03-17 09:16:55 +01:00
|
|
|
loadMoreButton.isHidden = false
|
|
|
|
loadMoreLabel.isHidden = false
|
|
|
|
activityIndicatorView.isHidden = false
|
|
|
|
|
2021-02-04 08:09:58 +01:00
|
|
|
loadMoreButton.setInsets(forContentPadding: .zero, imageTitlePadding: 4)
|
|
|
|
loadMoreButton.addTarget(self, action: #selector(TimelineMiddleLoaderTableViewCell.loadMoreButtonDidPressed(_:)), for: .touchUpInside)
|
2021-03-17 05:17:48 +01:00
|
|
|
|
2021-04-13 13:46:42 +02:00
|
|
|
topSawToothView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(topSawToothView)
|
2021-03-17 05:17:48 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2021-04-13 13:46:42 +02:00
|
|
|
topSawToothView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
|
|
topSawToothView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
|
|
|
topSawToothView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
|
|
|
topSawToothView.heightAnchor.constraint(equalToConstant: 3),
|
|
|
|
])
|
|
|
|
topSawToothView.transform = CGAffineTransform(scaleX: 1, y: -1) // upside down
|
|
|
|
|
|
|
|
bottomSawToothView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(bottomSawToothView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
bottomSawToothView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
|
|
|
bottomSawToothView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
|
|
|
bottomSawToothView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
bottomSawToothView.heightAnchor.constraint(equalToConstant: 3),
|
2021-03-17 05:17:48 +01:00
|
|
|
])
|
2021-02-04 08:09:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension TimelineMiddleLoaderTableViewCell {
|
|
|
|
@objc private func loadMoreButtonDidPressed(_ sender: UIButton) {
|
|
|
|
os_log("%{public}s[%{public}ld], %{public}s", (#file as NSString).lastPathComponent, #line, #function)
|
|
|
|
delegate?.timelineMiddleLoaderTableViewCell(self, loadMoreButtonDidPressed: sender)
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 12:08:30 +01:00
|
|
|
|
|
|
|
#if canImport(SwiftUI) && DEBUG
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TimelineMiddleLoaderTableViewCell_Previews: PreviewProvider {
|
|
|
|
|
|
|
|
static var previews: some View {
|
|
|
|
UIViewPreview(width: 375) {
|
|
|
|
TimelineMiddleLoaderTableViewCell()
|
|
|
|
}
|
|
|
|
.previewLayout(.fixed(width: 375, height: 100))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|