Roll back call text views

This commit is contained in:
Isaac 2024-12-10 22:30:37 +08:00
parent a1880941e9
commit 0d4dc2a7c7
2 changed files with 9 additions and 23 deletions

View File

@ -70,7 +70,6 @@ swift_library(
"//submodules/AppBundle", "//submodules/AppBundle",
"//submodules/UIKitRuntimeUtils", "//submodules/UIKitRuntimeUtils",
"//submodules/TelegramPresentationData", "//submodules/TelegramPresentationData",
"//submodules/Components/MultilineTextComponent",
], ],
visibility = [ visibility = [
"//visibility:public", "//visibility:public",

View File

@ -1,7 +1,6 @@
import Foundation import Foundation
import UIKit import UIKit
import ComponentFlow import ComponentFlow
import MultilineTextComponent
final class TextView: UIView { final class TextView: UIView {
private struct Params: Equatable { private struct Params: Equatable {
@ -22,8 +21,6 @@ final class TextView: UIView {
private var layoutState: LayoutState? private var layoutState: LayoutState?
private var animateContentsTransition: Bool = false private var animateContentsTransition: Bool = false
private let content = ComponentView<Empty>()
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: CGRect()) super.init(frame: CGRect())
@ -59,25 +56,17 @@ final class TextView: UIView {
font = UIFont.systemFont(ofSize: fontSize, weight: UIFont.Weight(fontWeight)) font = UIFont.systemFont(ofSize: fontSize, weight: UIFont.Weight(fontWeight))
} }
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = alignment
paragraphStyle.lineSpacing = 0.6
let attributedString = NSAttributedString(string: string, attributes: [ let attributedString = NSAttributedString(string: string, attributes: [
.font: font, .font: font,
.foregroundColor: color, .foregroundColor: color,
.paragraphStyle: paragraphStyle
]) ])
let stringBounds = attributedString.boundingRect(with: CGSize(width: constrainedWidth, height: 200.0), options: .usesLineFragmentOrigin, context: nil)
let contentSize = self.content.update( let stringSize = CGSize(width: ceil(stringBounds.width), height: ceil(stringBounds.height))
transition: .immediate, let size = CGSize(width: min(constrainedWidth, stringSize.width), height: stringSize.height)
component: AnyComponent(MultilineTextComponent(
text: .plain(attributedString),
horizontalAlignment: alignment
)),
environment: {},
containerSize: CGSize(width: constrainedWidth, height: 1000.0)
)
if let contentView = self.content.view {
contentView.frame = CGRect(origin: CGPoint(), size: contentSize)
}
let size = CGSize(width: min(constrainedWidth, contentSize.width), height: contentSize.height)
let layoutState = LayoutState(params: params, size: size, attributedString: attributedString) let layoutState = LayoutState(params: params, size: size, attributedString: attributedString)
if self.layoutState != layoutState { if self.layoutState != layoutState {
@ -90,12 +79,10 @@ final class TextView: UIView {
} }
override func draw(_ rect: CGRect) { override func draw(_ rect: CGRect) {
guard let _ = self.layoutState else { guard let layoutState = self.layoutState else {
return return
} }
if let contentView = self.content.view { layoutState.attributedString.draw(with: rect, options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin], context: nil)
contentView.draw(contentView.bounds)
}
} }
} }