Compare commits

...

2 Commits

Author SHA1 Message Date
2f8c1f3514 add limit lines 2025-10-23 18:41:14 +03:00
fa1637a5af fix warning 2025-10-23 18:35:52 +03:00

View File

@ -7,6 +7,8 @@ struct PrivateChatView: View {
let chat: PrivateChatListItem let chat: PrivateChatListItem
let currentUserId: String? let currentUserId: String?
private let bottomAnchorId = "PrivateChatBottomAnchor" private let bottomAnchorId = "PrivateChatBottomAnchor"
let lineLimitInChat = 6
@StateObject private var viewModel: PrivateChatViewModel @StateObject private var viewModel: PrivateChatViewModel
@State private var hasPositionedToBottom: Bool = false @State private var hasPositionedToBottom: Bool = false
@ -247,9 +249,9 @@ struct PrivateChatView: View {
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
Group { Group {
if #available(iOS 160.0, *) { if #available(iOS 16.0, *) {
TextField(inputTab.placeholder, text: $draftText, axis: .vertical) TextField(inputTab.placeholder, text: $draftText, axis: .vertical)
.lineLimit(1...4) .lineLimit(1...lineLimitInChat)
.focused($isComposerFocused) .focused($isComposerFocused)
.submitLabel(.send) .submitLabel(.send)
.disabled(currentUserId == nil) .disabled(currentUserId == nil)
@ -264,7 +266,7 @@ struct PrivateChatView: View {
), ),
isEnabled: currentUserId != nil, isEnabled: currentUserId != nil,
minHeight: 10, minHeight: 10,
maxLines: 4, maxLines: lineLimitInChat,
calculatedHeight: $legacyComposerHeight, calculatedHeight: $legacyComposerHeight,
onSubmit: sendCurrentMessage onSubmit: sendCurrentMessage
) )
@ -504,7 +506,12 @@ private struct LegacyMultilineTextView: UIViewRepresentable {
context.coordinator.updatePlaceholderVisibility(for: textView) context.coordinator.updatePlaceholderVisibility(for: textView)
DispatchQueue.main.async { DispatchQueue.main.async {
Self.recalculateHeight(for: textView, result: calculatedHeightBinding, minHeight: minHeight, maxLines: maxLines) Self.recalculateHeight(
for: textView,
result: calculatedHeightBinding,
minHeight: minHeight,
maxLines: maxLines
)
} }
return textView return textView
@ -534,7 +541,12 @@ private struct LegacyMultilineTextView: UIViewRepresentable {
uiView.resignFirstResponder() uiView.resignFirstResponder()
} }
Self.recalculateHeight(for: uiView, result: calculatedHeightBinding, minHeight: minHeight, maxLines: maxLines) Self.recalculateHeight(
for: uiView,
result: calculatedHeightBinding,
minHeight: minHeight,
maxLines: maxLines
)
} }
func makeCoordinator() -> Coordinator { func makeCoordinator() -> Coordinator {
@ -559,12 +571,18 @@ private struct LegacyMultilineTextView: UIViewRepresentable {
let lineHeight = textView.font?.lineHeight ?? UIFont.preferredFont(forTextStyle: .body).lineHeight let lineHeight = textView.font?.lineHeight ?? UIFont.preferredFont(forTextStyle: .body).lineHeight
let maxHeight = minHeight + lineHeight * CGFloat(max(maxLines - 1, 0)) let maxHeight = minHeight + lineHeight * CGFloat(max(maxLines - 1, 0))
let clampedHeight = min(max(targetSize.height, minHeight), maxHeight) let clampedHeight = min(max(targetSize.height, minHeight), maxHeight)
let shouldScroll = targetSize.height > maxHeight + 0.5
if abs(result.wrappedValue - clampedHeight) > 0.5 { if abs(result.wrappedValue - clampedHeight) > 0.5 {
result.wrappedValue = clampedHeight let newHeight = clampedHeight
DispatchQueue.main.async {
if abs(result.wrappedValue - newHeight) > 0.5 {
result.wrappedValue = newHeight
}
}
} }
textView.isScrollEnabled = targetSize.height > maxHeight + 0.5 textView.isScrollEnabled = shouldScroll
} }
final class Coordinator: NSObject, UITextViewDelegate { final class Coordinator: NSObject, UITextViewDelegate {