From 784e20a993e32096f0e799a614abcda34b6ab0ba Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 24 Oct 2023 14:52:54 +0400 Subject: [PATCH] Input message preview improvements --- ...SendMessageActionSheetControllerNode.swift | 28 +++++++++++++++-- .../ChatItemGalleryFooterContentNode.swift | 2 ++ .../Sources/ChatInputTextNode.swift | 30 +++++++++++++++++++ .../Sources/ChatTextInputPanelNode.swift | 3 +- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift b/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift index 4f43901702..bff3646adc 100644 --- a/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift @@ -262,6 +262,18 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, if let attributedText = textInputView.attributedText, !attributedText.string.isEmpty { self.animateInputField = true + if let textInputView = self.textInputView as? ChatInputTextView { + self.fromMessageTextNode.textView.theme = textInputView.theme + + let mainColor = presentationData.theme.chat.message.outgoing.accentControlColor + self.toMessageTextNode.textView.theme = ChatInputTextView.Theme( + quote: ChatInputTextView.Theme.Quote( + background: mainColor.withMultipliedAlpha(0.1), + foreground: mainColor, + isDashed: textInputView.theme?.quote.isDashed == true + ) + ) + } self.fromMessageTextNode.attributedText = attributedText if let toAttributedText = self.fromMessageTextNode.attributedText?.mutableCopy() as? NSMutableAttributedString { @@ -702,6 +714,9 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, messageFrame.size.width += 32.0 messageFrame.origin.x -= 13.0 messageFrame.origin.y = layout.size.height - messageFrame.origin.y - messageFrame.size.height - 1.0 + + let messageHeightAddition: CGFloat = max(0.0, 35.0 - messageFrame.size.height) + if inputHeight.isZero || layout.isNonExclusive { messageFrame.origin.y += menuHeightWithInset } @@ -732,17 +747,26 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, let clipFrame = messageFrame transition.updateFrame(node: self.messageClipNode, frame: clipFrame) - let backgroundFrame = CGRect(origin: CGPoint(), size: messageFrame.size) + var backgroundFrame = CGRect(origin: CGPoint(), size: messageFrame.size) + backgroundFrame.origin.y -= messageHeightAddition * 0.5 + backgroundFrame.size.height += messageHeightAddition transition.updateFrame(node: self.messageBackgroundNode, frame: backgroundFrame) var textFrame = self.textFieldFrame textFrame.origin = CGPoint(x: 13.0, y: 6.0 - UIScreenPixel) textFrame.size.height = self.textInputView.contentSize.height + if let textInputView = self.textInputView as? ChatInputTextView { + textFrame.origin.y -= 5.0 + + self.fromMessageTextNode.textView.defaultTextContainerInset = textInputView.defaultTextContainerInset + self.toMessageTextNode.textView.defaultTextContainerInset = textInputView.defaultTextContainerInset + } + /*if let textInputView = self.textInputView as? ChatInputTextView { textFrame.size.width -= textInputView.defaultTextContainerInset.right } else { textFrame.size.width -= self.textInputView.textContainerInset.right - } + }*/ if self.textInputView.isRTL { textFrame.origin.x -= messageOriginDelta diff --git a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift index a4b53115a7..95d13978c4 100644 --- a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift @@ -553,6 +553,8 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll return false } else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { return false + } else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.Timecode)] { + return false } else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention { return false } else if let _ = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String { diff --git a/submodules/TelegramUI/Components/Chat/ChatInputTextNode/Sources/ChatInputTextNode.swift b/submodules/TelegramUI/Components/Chat/ChatInputTextNode/Sources/ChatInputTextNode.swift index ca82a06e8c..706d9e1fa9 100644 --- a/submodules/TelegramUI/Components/Chat/ChatInputTextNode/Sources/ChatInputTextNode.swift +++ b/submodules/TelegramUI/Components/Chat/ChatInputTextNode/Sources/ChatInputTextNode.swift @@ -319,6 +319,9 @@ public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDele private let measurementTextStorage: NSTextStorage private let measurementLayoutManager: NSLayoutManager + private var validLayoutSize: CGSize? + private var isUpdatingLayout: Bool = false + private var blockQuotes: [Int: QuoteBackgroundView] = [:] public var defaultTextContainerInset: UIEdgeInsets = UIEdgeInsets() { @@ -346,6 +349,12 @@ public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDele return super.textInputMode } + override public var bounds: CGRect { + didSet { + assert(true) + } + } + public init() { self.customTextContainer = ChatInputTextContainer(size: CGSize(width: 100.0, height: 100000.0)) self.customLayoutManager = NSLayoutManager() @@ -407,6 +416,20 @@ public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDele fatalError("init(coder:) has not been implemented") } + override public func scrollRectToVisible(_ rect: CGRect, animated: Bool) { + var rect = rect + if rect.maxY > self.contentSize.height - 8.0 { + rect = CGRect(origin: CGPoint(x: rect.minX, y: self.contentSize.height - 1.0), size: CGSize(width: rect.width, height: 1.0)) + } + + var animated = animated + if self.isUpdatingLayout { + animated = false + } + + super.scrollRectToVisible(rect, animated: animated) + } + @objc public func layoutManager(_ layoutManager: NSLayoutManager, paragraphSpacingBeforeGlyphAt glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat { guard let textStorage = layoutManager.textStorage else { return 0.0 @@ -536,7 +559,14 @@ public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDele } override public func layoutSubviews() { + let isLayoutUpdated = self.validLayoutSize != self.bounds.size + self.validLayoutSize = self.bounds.size + + self.isUpdatingLayout = isLayoutUpdated + super.layoutSubviews() + + self.isUpdatingLayout = false } public func updateTextElements() { diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index 3c20c89f47..5c5abd156f 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -2284,7 +2284,8 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch textInputNode.textContainerInset = textInputViewRealInsets let textFieldFrame = CGRect(origin: CGPoint(x: self.textInputViewInternalInsets.left, y: self.textInputViewInternalInsets.top), size: CGSize(width: textInputFrame.size.width - (self.textInputViewInternalInsets.left + self.textInputViewInternalInsets.right), height: textInputFrame.size.height - self.textInputViewInternalInsets.top - textInputViewInternalInsets.bottom)) let shouldUpdateLayout = textFieldFrame.size != textInputNode.frame.size - transition.updateFrame(node: textInputNode, frame: textFieldFrame) + //transition.updateFrame(node: textInputNode, frame: textFieldFrame) + textInputNode.frame = textFieldFrame textInputNode.updateLayout(size: textFieldFrame.size) self.updateInputField(textInputFrame: textFieldFrame, transition: Transition(transition)) if shouldUpdateLayout {