2020-08-31 19:28:50 -04:00
|
|
|
//
|
|
|
|
// ComposeReplyContentView.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/22/20.
|
|
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ComposeReplyContentView: UIViewRepresentable {
|
|
|
|
typealias UIViewType = ComposeReplyContentTextView
|
|
|
|
|
|
|
|
let status: StatusMO
|
|
|
|
|
|
|
|
@EnvironmentObject var mastodonController: MastodonController
|
|
|
|
|
2020-09-06 22:47:02 -04:00
|
|
|
let heightChanged: (CGFloat) -> Void
|
|
|
|
|
2022-11-07 22:55:39 -05:00
|
|
|
func makeUIView(context: Context) -> UIViewType {
|
2020-08-31 19:28:50 -04:00
|
|
|
let view = ComposeReplyContentTextView()
|
|
|
|
view.overrideMastodonController = mastodonController
|
|
|
|
view.setTextFrom(status: status)
|
|
|
|
view.isUserInteractionEnabled = false
|
2022-11-07 22:55:39 -05:00
|
|
|
// scroll needs to be enabled, otherwise the text view never reports a contentSize greater than 1 line
|
|
|
|
view.isScrollEnabled = true
|
2020-08-31 19:28:50 -04:00
|
|
|
view.backgroundColor = .clear
|
2022-09-17 20:46:57 -04:00
|
|
|
view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
2020-09-06 22:47:02 -04:00
|
|
|
|
2020-08-31 19:28:50 -04:00
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
2022-11-07 22:55:39 -05:00
|
|
|
func updateUIView(_ uiView: UIViewType, context: Context) {
|
2020-09-06 22:47:02 -04:00
|
|
|
uiView.heightChanged = heightChanged
|
2020-08-31 19:28:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ComposeReplyContentTextView: StatusContentTextView {
|
2020-09-06 22:47:02 -04:00
|
|
|
var heightChanged: ((CGFloat) -> Void)?
|
2020-08-31 19:28:50 -04:00
|
|
|
|
2020-09-06 22:47:02 -04:00
|
|
|
override func layoutSubviews() {
|
|
|
|
super.layoutSubviews()
|
2020-08-31 19:28:50 -04:00
|
|
|
|
2020-09-06 22:47:02 -04:00
|
|
|
heightChanged?(contentSize.height)
|
2020-08-31 19:28:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|