Фикс: поднятие контента сообщений синхронно с раскрытием клавиатуры
This commit is contained in:
@@ -111,6 +111,7 @@ struct ChatTextInput: UIViewRepresentable {
|
||||
@Binding var isFocused: Bool
|
||||
var onKeyboardHeightChange: (CGFloat) -> Void
|
||||
var onUserTextInsertion: () -> Void = {}
|
||||
var onMultilineChange: (Bool) -> Void = { _ in }
|
||||
var font: UIFont = .systemFont(ofSize: 17, weight: .regular)
|
||||
var textColor: UIColor = .white
|
||||
var placeholderColor: UIColor = UIColor.white.withAlphaComponent(0.35)
|
||||
@@ -195,6 +196,7 @@ struct ChatTextInput: UIViewRepresentable {
|
||||
final class Coordinator: NSObject, UITextViewDelegate {
|
||||
var parent: ChatTextInput
|
||||
var isUpdatingText = false
|
||||
private var wasMultiline = false
|
||||
private var pendingFocusSync: DispatchWorkItem?
|
||||
|
||||
init(parent: ChatTextInput) {
|
||||
@@ -248,6 +250,17 @@ struct ChatTextInput: UIViewRepresentable {
|
||||
|
||||
func invalidateHeight(_ tv: UITextView) {
|
||||
tv.invalidateIntrinsicContentSize()
|
||||
checkMultiline(tv)
|
||||
}
|
||||
|
||||
private func checkMultiline(_ tv: UITextView) {
|
||||
let lineHeight = tv.font?.lineHeight ?? 20
|
||||
let singleLineHeight = lineHeight + tv.textContainerInset.top + tv.textContainerInset.bottom
|
||||
let isMultiline = tv.contentSize.height > singleLineHeight + 0.5
|
||||
if isMultiline != wasMultiline {
|
||||
wasMultiline = isMultiline
|
||||
parent.onMultilineChange(isMultiline)
|
||||
}
|
||||
}
|
||||
|
||||
func syncFocus(for tv: UITextView) {
|
||||
|
||||
Reference in New Issue
Block a user