Input message preview improvements

This commit is contained in:
Ali 2023-10-24 14:52:54 +04:00
parent 104e1ede45
commit 784e20a993
4 changed files with 60 additions and 3 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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() {

View File

@ -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 {