Tusker/Tusker/Screens/Compose/ComposeReplyContentView.swift

49 lines
1.3 KiB
Swift

//
// 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
let maxWidth: CGFloat
@EnvironmentObject var mastodonController: MastodonController
func makeUIView(context: Context) -> ComposeReplyContentTextView {
let view = ComposeReplyContentTextView()
view.overrideMastodonController = mastodonController
view.setTextFrom(status: status)
view.isScrollEnabled = false
view.isUserInteractionEnabled = false
view.backgroundColor = .clear
view.maxWidth = maxWidth
return view
}
func updateUIView(_ uiView: ComposeReplyContentTextView, context: Context) {
uiView.constraint.constant = maxWidth
}
}
class ComposeReplyContentTextView: StatusContentTextView {
var maxWidth: CGFloat!
var constraint: NSLayoutConstraint!
override func didMoveToSuperview() {
super.didMoveToSuperview()
translatesAutoresizingMaskIntoConstraints = false
constraint = widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth)
constraint.isActive = true
}
}