Skip to content

Fix comment width #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions V2er/View/Widget/RichText/RichText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,23 @@ fileprivate struct AttributedText: UIViewRepresentable {
self._height = height
}

func makeUIView(context: Context) -> MaxWidthAttributedLabel {
let label = MaxWidthAttributedLabel()
func makeUIView(context: Context) -> AttributedLabel {
let label = AttributedLabel()
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
label.attributedText = self.richString
label.maxWidth = maxWidth
clickEvent(label: label)
return label
}

func updateUIView(_ label: MaxWidthAttributedLabel, context: Context) {
func updateUIView(_ label: AttributedLabel, context: Context) {
label.attributedText = self.richString
label.maxWidth = maxWidth
runInMain(delay: 100) {
self.height = label.sizeThatFits(CGSize(width: maxWidth, height: .infinity)).height
}
}

private func clickEvent(label: MaxWidthAttributedLabel) {
private func clickEvent(label: AttributedLabel) {
let baseURL = APIService.baseUrlString
label.onClick = { label, detection in
if let consumed = self.detection?(detection.type) {
Expand Down Expand Up @@ -106,14 +104,6 @@ fileprivate struct AttributedText: UIViewRepresentable {

}

fileprivate class MaxWidthAttributedLabel: AttributedLabel {
var maxWidth: CGFloat!

open override var intrinsicContentSize: CGSize {
sizeThatFits(CGSize(width: maxWidth, height: .infinity))
}
}

extension String {
func rich(baseStyle: Atributika.Style = RichText.Styles.base) ->RichString {
return self
Expand Down