From 6c152650a1c90aa705ed8c3b46ec3be1dc937c4f Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Thu, 18 Jan 2024 18:03:17 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20-=20=EB=A7=81=ED=81=AC=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../All/CreatorCommunityAllItemView.swift | 39 +++++++++++++------ .../Room/V2/Component/Text/TextView.swift | 4 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift index cd68b96..a934330 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllItemView.swift @@ -16,9 +16,9 @@ struct CreatorCommunityAllItemView: View { let onClickWriteComment: (String) -> Void let onClickShowReportMenu: () -> Void - @State var isExpandContent = false @State var isLike = false @State var likeCount = 0 + @State private var textHeight: CGFloat = .zero init( item: GetCommunityPostListResponse, @@ -48,11 +48,11 @@ struct CreatorCommunityAllItemView: View { VStack(alignment: .leading, spacing: 3) { Text(item.creatorNickname) .font(.custom(Font.medium.rawValue, size: 13.3)) - .foregroundColor(Color(hex: "eeeeee")) + .foregroundColor(Color.grayee) Text(item.date) .font(.custom(Font.light.rawValue, size: 13.3)) - .foregroundColor(Color(hex: "777777")) + .foregroundColor(Color.gray77) } .padding(.leading, 11) @@ -63,13 +63,23 @@ struct CreatorCommunityAllItemView: View { .onTapGesture { onClickShowReportMenu() } } - Text(item.content) - .font(.custom(Font.medium.rawValue, size: 13.3)) - .foregroundColor(Color(hex: "bbbbbb")) - .fixedSize(horizontal: false, vertical: true) - .frame(maxWidth: .infinity, alignment: .leading) - .lineLimit(isExpandContent ? Int.max : 3) - .onTapGesture { isExpandContent.toggle() } + DetectableTextView(text: item.content, textSize: 13.3, font: Font.medium.rawValue) + .frame( + width: screenSize().width - 16, + height: textHeight + ) + .onAppear { + self.textHeight = self.estimatedHeight( + for: item.content, + width: screenSize().width - 16 + ) + } + .onChange(of: item.content) { newText in + self.textHeight = self.estimatedHeight( + for: newText, + width: screenSize().width - 16 + ) + } if let imageUrl = item.imageUrl { KFImage(URL(string: imageUrl)) @@ -112,9 +122,16 @@ struct CreatorCommunityAllItemView: View { } .padding(.horizontal, 8) .padding(.vertical, 11) - .background(Color(hex: "222222")) + .background(Color.gray22) .cornerRadius(5.3) } + + private func estimatedHeight(for text: String, width: CGFloat) -> CGFloat { + let textView = UITextView(frame: CGRect(x: 0, y: 0, width: width, height: .greatestFiniteMagnitude)) + textView.font = UIFont.systemFont(ofSize: 13.3) + textView.text = text + return textView.sizeThatFits(CGSize(width: width, height: .greatestFiniteMagnitude)).height + } } struct CreatorCommunityAllItemView_Previews: PreviewProvider { diff --git a/SodaLive/Sources/Live/Room/V2/Component/Text/TextView.swift b/SodaLive/Sources/Live/Room/V2/Component/Text/TextView.swift index 02b89de..3e49609 100644 --- a/SodaLive/Sources/Live/Room/V2/Component/Text/TextView.swift +++ b/SodaLive/Sources/Live/Room/V2/Component/Text/TextView.swift @@ -10,6 +10,8 @@ import UIKit struct DetectableTextView: UIViewRepresentable { var text: String + var textSize: CGFloat = 11.3 + var font: String = Font.light.rawValue func makeUIView(context: Context) -> UITextView { let textView = UITextView() @@ -17,7 +19,7 @@ struct DetectableTextView: UIViewRepresentable { textView.backgroundColor = .clear textView.isScrollEnabled = true textView.dataDetectorTypes = .link - textView.font = UIFont(name: Font.light.rawValue, size: 11.3) + textView.font = UIFont(name: font, size: textSize) textView.textColor = .white textView.textContainer.lineFragmentPadding = 0 textView.textContainerInset = .zero