2020-08-31 23:28:50 +00:00
|
|
|
//
|
|
|
|
// ComposeReplyContentView.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/22/20.
|
|
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2023-04-16 17:23:13 +00:00
|
|
|
import Pachyderm
|
2020-08-31 23:28:50 +00:00
|
|
|
|
|
|
|
struct ComposeReplyContentView: UIViewRepresentable {
|
|
|
|
typealias UIViewType = ComposeReplyContentTextView
|
|
|
|
|
2023-04-16 17:23:13 +00:00
|
|
|
let status: any StatusProtocol
|
|
|
|
let mastodonController: MastodonController
|
2020-08-31 23:28:50 +00:00
|
|
|
|
2020-09-07 02:47:02 +00:00
|
|
|
let heightChanged: (CGFloat) -> Void
|
|
|
|
|
2022-11-08 03:55:39 +00:00
|
|
|
func makeUIView(context: Context) -> UIViewType {
|
2020-08-31 23:28:50 +00:00
|
|
|
let view = ComposeReplyContentTextView()
|
|
|
|
view.isUserInteractionEnabled = false
|
2022-11-08 03:55:39 +00:00
|
|
|
// scroll needs to be enabled, otherwise the text view never reports a contentSize greater than 1 line
|
|
|
|
view.isScrollEnabled = true
|
2020-08-31 23:28:50 +00:00
|
|
|
view.backgroundColor = .clear
|
2022-09-18 00:46:57 +00:00
|
|
|
view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
2020-09-07 02:47:02 +00:00
|
|
|
|
2023-04-16 17:23:13 +00:00
|
|
|
view.adjustsFontForContentSizeCategory = true
|
|
|
|
|
|
|
|
view.overrideMastodonController = mastodonController
|
2023-12-23 01:44:46 +00:00
|
|
|
view.attributedText = TimelineStatusCollectionViewCell.htmlConverter.convert(status.content)
|
2023-04-16 17:23:13 +00:00
|
|
|
|
2020-08-31 23:28:50 +00:00
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
2022-11-08 03:55:39 +00:00
|
|
|
func updateUIView(_ uiView: UIViewType, context: Context) {
|
2020-09-07 02:47:02 +00:00
|
|
|
uiView.heightChanged = heightChanged
|
2020-08-31 23:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ComposeReplyContentTextView: StatusContentTextView {
|
2020-09-07 02:47:02 +00:00
|
|
|
var heightChanged: ((CGFloat) -> Void)?
|
2020-08-31 23:28:50 +00:00
|
|
|
|
2020-09-07 02:47:02 +00:00
|
|
|
override func layoutSubviews() {
|
|
|
|
super.layoutSubviews()
|
2020-08-31 23:28:50 +00:00
|
|
|
|
2020-09-07 02:47:02 +00:00
|
|
|
heightChanged?(contentSize.height)
|
2020-08-31 23:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|