Tusker/Tusker/Screens/Compose/ComposeReplyContentView.swift

51 lines
1.4 KiB
Swift

//
// ComposeReplyContentView.swift
// Tusker
//
// Created by Shadowfacts on 8/22/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import SwiftUI
import Pachyderm
struct ComposeReplyContentView: UIViewRepresentable {
typealias UIViewType = ComposeReplyContentTextView
let status: any StatusProtocol
let mastodonController: MastodonController
let heightChanged: (CGFloat) -> Void
func makeUIView(context: Context) -> UIViewType {
let view = ComposeReplyContentTextView()
view.isUserInteractionEnabled = false
// scroll needs to be enabled, otherwise the text view never reports a contentSize greater than 1 line
view.isScrollEnabled = true
view.backgroundColor = .clear
view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
view.adjustsFontForContentSizeCategory = true
view.overrideMastodonController = mastodonController
view.attributedText = TimelineStatusCollectionViewCell.htmlConverter.convert(status.content)
return view
}
func updateUIView(_ uiView: UIViewType, context: Context) {
uiView.heightChanged = heightChanged
}
}
class ComposeReplyContentTextView: StatusContentTextView {
var heightChanged: ((CGFloat) -> Void)?
override func layoutSubviews() {
super.layoutSubviews()
heightChanged?(contentSize.height)
}
}