2021-03-11 08:41:27 +01:00
|
|
|
//
|
2021-03-17 11:09:38 +01:00
|
|
|
// ComposeStatusContentTableViewCell.swift
|
2021-03-11 08:41:27 +01:00
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-11.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2021-03-12 07:18:07 +01:00
|
|
|
import Combine
|
2021-03-11 12:26:10 +01:00
|
|
|
import TwitterTextEditor
|
2021-03-11 08:41:27 +01:00
|
|
|
|
2021-03-17 11:09:38 +01:00
|
|
|
final class ComposeStatusContentTableViewCell: UITableViewCell {
|
2021-03-11 08:41:27 +01:00
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
let statusView = StatusView()
|
2021-03-12 07:18:07 +01:00
|
|
|
|
2021-03-11 12:26:10 +01:00
|
|
|
let textEditorView: TextEditorView = {
|
|
|
|
let textEditorView = TextEditorView()
|
|
|
|
textEditorView.font = .preferredFont(forTextStyle: .body)
|
2021-03-12 07:18:07 +01:00
|
|
|
textEditorView.scrollView.isScrollEnabled = false
|
2021-03-11 12:26:10 +01:00
|
|
|
textEditorView.isScrollEnabled = false
|
2021-03-12 07:18:07 +01:00
|
|
|
textEditorView.placeholderText = L10n.Scene.Compose.contentInputPlaceholder
|
2021-03-15 06:44:29 +01:00
|
|
|
textEditorView.keyboardType = .twitter
|
2021-03-11 12:26:10 +01:00
|
|
|
return textEditorView
|
|
|
|
}()
|
2021-03-11 08:41:27 +01:00
|
|
|
|
2021-03-12 07:18:07 +01:00
|
|
|
let composeContent = PassthroughSubject<String, Never>()
|
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:09:38 +01:00
|
|
|
extension ComposeStatusContentTableViewCell {
|
2021-03-11 08:41:27 +01:00
|
|
|
|
|
|
|
private func _init() {
|
2021-03-11 12:26:10 +01:00
|
|
|
selectionStyle = .none
|
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
statusView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(statusView)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-03-11 12:26:10 +01:00
|
|
|
statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20),
|
|
|
|
statusView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
statusView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
2021-03-11 08:41:27 +01:00
|
|
|
])
|
2021-03-11 12:26:10 +01:00
|
|
|
statusView.statusContainerStackView.isHidden = true
|
|
|
|
statusView.actionToolbarContainer.isHidden = true
|
2021-03-16 09:17:11 +01:00
|
|
|
statusView.nameTrialingDotLabel.isHidden = true
|
|
|
|
statusView.dateLabel.isHidden = true
|
2021-03-11 12:26:10 +01:00
|
|
|
|
2021-03-17 11:09:38 +01:00
|
|
|
statusView.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
|
|
|
statusView.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
|
|
|
|
2021-03-11 12:26:10 +01:00
|
|
|
textEditorView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(textEditorView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
textEditorView.topAnchor.constraint(equalTo: statusView.bottomAnchor, constant: 10),
|
|
|
|
textEditorView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
|
|
|
|
textEditorView.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
|
|
|
|
contentView.bottomAnchor.constraint(equalTo: textEditorView.bottomAnchor, constant: 20),
|
|
|
|
textEditorView.heightAnchor.constraint(greaterThanOrEqualToConstant: 44).priority(.defaultHigh),
|
|
|
|
])
|
2021-03-17 11:09:38 +01:00
|
|
|
textEditorView.setContentCompressionResistancePriority(.required - 2, for: .vertical)
|
2021-03-11 12:26:10 +01:00
|
|
|
|
|
|
|
// TODO:
|
2021-03-12 07:18:07 +01:00
|
|
|
|
|
|
|
textEditorView.changeObserver = self
|
2021-03-11 12:26:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func didMoveToWindow() {
|
|
|
|
super.didMoveToWindow()
|
|
|
|
|
2021-03-11 08:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:09:38 +01:00
|
|
|
extension ComposeStatusContentTableViewCell {
|
2021-03-11 12:26:10 +01:00
|
|
|
|
|
|
|
}
|
2021-03-12 07:18:07 +01:00
|
|
|
|
|
|
|
// MARK: - UITextViewDelegate
|
2021-03-17 11:09:38 +01:00
|
|
|
extension ComposeStatusContentTableViewCell: TextEditorViewChangeObserver {
|
2021-03-12 07:18:07 +01:00
|
|
|
func textEditorView(_ textEditorView: TextEditorView, didChangeWithChangeResult changeResult: TextEditorViewChangeResult) {
|
|
|
|
guard changeResult.isTextChanged else { return }
|
|
|
|
composeContent.send(textEditorView.text)
|
|
|
|
}
|
|
|
|
}
|