Compare commits
No commits in common. "2f8c1f35145cad5f82f4ab8dfe761dff3c8174a2" and "b47922694d7915f1442a26b4061b2c7ee09e6c42" have entirely different histories.
2f8c1f3514
...
b47922694d
@ -7,8 +7,6 @@ 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
|
||||||
@ -249,9 +247,9 @@ struct PrivateChatView: View {
|
|||||||
|
|
||||||
ZStack(alignment: .bottomTrailing) {
|
ZStack(alignment: .bottomTrailing) {
|
||||||
Group {
|
Group {
|
||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 160.0, *) {
|
||||||
TextField(inputTab.placeholder, text: $draftText, axis: .vertical)
|
TextField(inputTab.placeholder, text: $draftText, axis: .vertical)
|
||||||
.lineLimit(1...lineLimitInChat)
|
.lineLimit(1...4)
|
||||||
.focused($isComposerFocused)
|
.focused($isComposerFocused)
|
||||||
.submitLabel(.send)
|
.submitLabel(.send)
|
||||||
.disabled(currentUserId == nil)
|
.disabled(currentUserId == nil)
|
||||||
@ -266,7 +264,7 @@ struct PrivateChatView: View {
|
|||||||
),
|
),
|
||||||
isEnabled: currentUserId != nil,
|
isEnabled: currentUserId != nil,
|
||||||
minHeight: 10,
|
minHeight: 10,
|
||||||
maxLines: lineLimitInChat,
|
maxLines: 4,
|
||||||
calculatedHeight: $legacyComposerHeight,
|
calculatedHeight: $legacyComposerHeight,
|
||||||
onSubmit: sendCurrentMessage
|
onSubmit: sendCurrentMessage
|
||||||
)
|
)
|
||||||
@ -506,12 +504,7 @@ private struct LegacyMultilineTextView: UIViewRepresentable {
|
|||||||
|
|
||||||
context.coordinator.updatePlaceholderVisibility(for: textView)
|
context.coordinator.updatePlaceholderVisibility(for: textView)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
Self.recalculateHeight(
|
Self.recalculateHeight(for: textView, result: calculatedHeightBinding, minHeight: minHeight, maxLines: maxLines)
|
||||||
for: textView,
|
|
||||||
result: calculatedHeightBinding,
|
|
||||||
minHeight: minHeight,
|
|
||||||
maxLines: maxLines
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return textView
|
return textView
|
||||||
@ -541,12 +534,7 @@ private struct LegacyMultilineTextView: UIViewRepresentable {
|
|||||||
uiView.resignFirstResponder()
|
uiView.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
Self.recalculateHeight(
|
Self.recalculateHeight(for: uiView, result: calculatedHeightBinding, minHeight: minHeight, maxLines: maxLines)
|
||||||
for: uiView,
|
|
||||||
result: calculatedHeightBinding,
|
|
||||||
minHeight: minHeight,
|
|
||||||
maxLines: maxLines
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCoordinator() -> Coordinator {
|
func makeCoordinator() -> Coordinator {
|
||||||
@ -571,18 +559,12 @@ 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 {
|
||||||
let newHeight = clampedHeight
|
result.wrappedValue = clampedHeight
|
||||||
DispatchQueue.main.async {
|
|
||||||
if abs(result.wrappedValue - newHeight) > 0.5 {
|
|
||||||
result.wrappedValue = newHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textView.isScrollEnabled = shouldScroll
|
textView.isScrollEnabled = targetSize.height > maxHeight + 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
final class Coordinator: NSObject, UITextViewDelegate {
|
final class Coordinator: NSObject, UITextViewDelegate {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user