2021-03-23 11:47:21 +01:00
|
|
|
//
|
2021-03-24 07:49:27 +01:00
|
|
|
// ComposeStatusPollOptionAppendEntryCollectionViewCell.swift
|
2021-03-23 11:47:21 +01:00
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-23.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
|
2021-05-08 05:03:34 +02:00
|
|
|
protocol ComposeStatusPollOptionAppendEntryCollectionViewCellDelegate: AnyObject {
|
2021-03-24 07:49:27 +01:00
|
|
|
func composeStatusPollOptionAppendEntryCollectionViewCellDidPressed(_ cell: ComposeStatusPollOptionAppendEntryCollectionViewCell)
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|
|
|
|
|
2021-03-24 07:49:27 +01:00
|
|
|
final class ComposeStatusPollOptionAppendEntryCollectionViewCell: UICollectionViewCell {
|
2021-03-24 08:46:40 +01:00
|
|
|
|
2021-03-23 11:47:21 +01:00
|
|
|
let pollOptionView = PollOptionView()
|
2021-03-24 08:46:40 +01:00
|
|
|
let reorderBarImageView: UIImageView = {
|
|
|
|
let imageView = UIImageView()
|
|
|
|
imageView.contentMode = .scaleAspectFit
|
|
|
|
imageView.image = UIImage(systemName: "line.horizontal.3")?.withConfiguration(UIImage.SymbolConfiguration(pointSize: 20, weight: .regular)).withRenderingMode(.alwaysTemplate)
|
|
|
|
imageView.tintColor = Asset.Colors.Label.secondary.color
|
|
|
|
return imageView
|
|
|
|
}()
|
2021-03-23 11:47:21 +01:00
|
|
|
|
|
|
|
let singleTagGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
|
|
|
|
|
2021-03-24 08:46:40 +01:00
|
|
|
weak var delegate: ComposeStatusPollOptionAppendEntryCollectionViewCellDelegate?
|
|
|
|
|
2021-03-23 11:47:21 +01:00
|
|
|
override var isHighlighted: Bool {
|
|
|
|
didSet {
|
2021-07-05 10:07:17 +02:00
|
|
|
pollOptionView.roundedBackgroundView.backgroundColor = isHighlighted ? ThemeService.shared.currentTheme.value.tertiarySystemGroupedBackgroundColor.withAlphaComponent(0.6) : ThemeService.shared.currentTheme.value.tertiarySystemGroupedBackgroundColor
|
2021-06-22 14:52:30 +02:00
|
|
|
pollOptionView.plusCircleImageView.tintColor = isHighlighted ? Asset.Colors.brandBlue.color.withAlphaComponent(0.5) : Asset.Colors.brandBlue.color
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 08:46:40 +01:00
|
|
|
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
|
|
|
|
return pollOptionView.frame.contains(point)
|
|
|
|
}
|
2021-03-23 11:47:21 +01:00
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
|
|
|
|
delegate = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-24 07:49:27 +01:00
|
|
|
extension ComposeStatusPollOptionAppendEntryCollectionViewCell {
|
2021-03-23 11:47:21 +01:00
|
|
|
|
|
|
|
private func _init() {
|
|
|
|
pollOptionView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(pollOptionView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
pollOptionView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
|
|
pollOptionView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
pollOptionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
])
|
|
|
|
|
2021-03-24 08:46:40 +01:00
|
|
|
reorderBarImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(reorderBarImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
reorderBarImageView.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
|
|
reorderBarImageView.leadingAnchor.constraint(equalTo: pollOptionView.trailingAnchor, constant: ComposeStatusPollOptionCollectionViewCell.reorderHandlerImageLeadingMargin),
|
|
|
|
reorderBarImageView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
|
|
|
reorderBarImageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
])
|
|
|
|
|
2021-03-23 11:47:21 +01:00
|
|
|
pollOptionView.checkmarkImageView.isHidden = true
|
|
|
|
pollOptionView.checkmarkBackgroundView.isHidden = true
|
|
|
|
pollOptionView.optionPercentageLabel.isHidden = true
|
|
|
|
pollOptionView.optionTextField.isHidden = true
|
|
|
|
pollOptionView.plusCircleImageView.isHidden = false
|
|
|
|
|
2021-07-05 10:07:17 +02:00
|
|
|
pollOptionView.roundedBackgroundView.backgroundColor = ThemeService.shared.currentTheme.value.tertiarySystemGroupedBackgroundColor
|
2021-03-23 11:47:21 +01:00
|
|
|
setupBorderColor()
|
|
|
|
|
|
|
|
pollOptionView.addGestureRecognizer(singleTagGestureRecognizer)
|
2021-03-24 07:49:27 +01:00
|
|
|
singleTagGestureRecognizer.addTarget(self, action: #selector(ComposeStatusPollOptionAppendEntryCollectionViewCell.singleTagGestureRecognizerHandler(_:)))
|
2021-03-24 08:46:40 +01:00
|
|
|
|
|
|
|
reorderBarImageView.isHidden = true
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private func setupBorderColor() {
|
|
|
|
pollOptionView.roundedBackgroundView.layer.borderWidth = 1
|
2021-07-05 10:07:17 +02:00
|
|
|
pollOptionView.roundedBackgroundView.layer.borderColor = ThemeService.shared.currentTheme.value.tableViewCellSelectionBackgroundColor.withAlphaComponent(0.3).cgColor
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
|
|
|
|
setupBorderColor()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-24 07:49:27 +01:00
|
|
|
extension ComposeStatusPollOptionAppendEntryCollectionViewCell {
|
2021-03-23 11:47:21 +01:00
|
|
|
|
|
|
|
@objc private func singleTagGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
|
|
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
2021-03-24 07:49:27 +01:00
|
|
|
delegate?.composeStatusPollOptionAppendEntryCollectionViewCellDidPressed(self)
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if canImport(SwiftUI) && DEBUG
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ComposeStatusNewPollOptionCollectionViewCell_Previews: PreviewProvider {
|
|
|
|
|
|
|
|
static var controls: some View {
|
|
|
|
Group {
|
|
|
|
UIViewPreview() {
|
2021-03-24 07:49:27 +01:00
|
|
|
let cell = ComposeStatusPollOptionAppendEntryCollectionViewCell()
|
2021-03-23 11:47:21 +01:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
.previewLayout(.fixed(width: 375, height: 44 + 10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static var previews: some View {
|
|
|
|
Group {
|
|
|
|
controls.colorScheme(.light)
|
|
|
|
controls.colorScheme(.dark)
|
|
|
|
}
|
|
|
|
.background(Color.gray)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|