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

84 lines
2.9 KiB
Swift
Raw Normal View History

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
protocol TimelineMiddleLoaderTableViewCellDelegate: AnyObject {
2021-02-04 08:09:58 +01:00
func timelineMiddleLoaderTableViewCell(_ cell: TimelineMiddleLoaderTableViewCell, loadMoreButtonDidPressed button: UIButton)
}
final class TimelineMiddleLoaderTableViewCell: TimelineLoaderTableViewCell {
2021-02-04 08:09:58 +01:00
weak var delegate: TimelineMiddleLoaderTableViewCellDelegate?
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()
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)
}
}
#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