Added forward placeholder in message sending preview

This commit is contained in:
Ilya Laktyushin
2019-07-30 18:49:04 +03:00
parent 070a156405
commit 5da86bd619
2 changed files with 39 additions and 15 deletions

View File

@@ -32,7 +32,7 @@ final class ChatSendMessageActionSheetController: ViewController {
self.sendButtonFrame = sendButtonFrame
self.textInputNode = textInputNode
self.completion = completion
super.init(navigationBarPresentationData: nil)
self.presentationDataDisposable = (context.sharedContext.presentationData
@@ -55,12 +55,12 @@ final class ChatSendMessageActionSheetController: ViewController {
}
override func loadDisplayNode() {
var accessoryPanelNode: AccessoryPanelNode?
if let panel = accessoryPanelForChatPresentationIntefaceState(self.interfaceState, context: self.context, currentPanel: nil, interfaceInteraction: nil), panel is ReplyAccessoryPanelNode || panel is ForwardAccessoryPanelNode {
accessoryPanelNode = panel
var forwardedCount = 0
if let forwardMessageIds = self.interfaceState.interfaceState.forwardMessageIds {
forwardedCount = forwardMessageIds.count
}
self.displayNode = ChatSendMessageActionSheetControllerNode(context: self.context, sendButtonFrame: self.sendButtonFrame, textInputNode: self.textInputNode, accessoryPanelNode: accessoryPanelNode, send: { [weak self] in
self.displayNode = ChatSendMessageActionSheetControllerNode(context: self.context, sendButtonFrame: self.sendButtonFrame, textInputNode: self.textInputNode, forwardedCount: forwardedCount, send: { [weak self] in
self?.controllerInteraction?.sendCurrentMessage(false)
self?.dismiss(cancel: false)
}, sendSilently: { [weak self] in

View File

@@ -105,6 +105,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
private let textFieldFrame: CGRect
private let textInputNode: EditableTextNode
private let accessoryPanelNode: AccessoryPanelNode?
private let forwardedCount: Int?
private let send: (() -> Void)?
private let cancel: (() -> Void)?
@@ -127,12 +128,14 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
private var validLayout: ContainerViewLayout?
init(context: AccountContext, sendButtonFrame: CGRect, textInputNode: EditableTextNode, accessoryPanelNode: AccessoryPanelNode?, send: (() -> Void)?, sendSilently: (() -> Void)?, cancel: (() -> Void)?) {
init(context: AccountContext, sendButtonFrame: CGRect, textInputNode: EditableTextNode, forwardedCount: Int?, send: (() -> Void)?, sendSilently: (() -> Void)?, cancel: (() -> Void)?) {
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
self.sendButtonFrame = sendButtonFrame
self.textFieldFrame = textInputNode.convert(textInputNode.bounds, to: nil)
self.textInputNode = textInputNode
self.accessoryPanelNode = accessoryPanelNode
self.accessoryPanelNode = nil
self.forwardedCount = forwardedCount
self.send = send
self.cancel = cancel
@@ -198,9 +201,13 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.sendButtonNode.setImage(PresentationResourcesChat.chatInputPanelSendButtonImage(self.presentationData.theme), for: [])
self.sendButtonNode.addTarget(self, action: #selector(sendButtonPressed), forControlEvents: .touchUpInside)
self.fromMessageTextNode.attributedText = textInputNode.attributedText
if let toAttributedText = textInputNode.attributedText?.mutableCopy() as? NSMutableAttributedString {
if let attributedText = textInputNode.attributedText, !attributedText.string.isEmpty {
self.fromMessageTextNode.attributedText = attributedText
} else {
self.fromMessageTextNode.attributedText = NSAttributedString(string: self.presentationData.strings.ForwardedMessages(Int32(forwardedCount ?? 0)), attributes: [NSAttributedStringKey.foregroundColor: self.presentationData.theme.chat.message.outgoing.primaryTextColor, NSAttributedStringKey.font: Font.regular(self.presentationData.fontSize.baseDisplaySize)])
}
if let toAttributedText = self.fromMessageTextNode.attributedText?.mutableCopy() as? NSMutableAttributedString {
toAttributedText.addAttribute(NSAttributedStringKey.foregroundColor, value: self.presentationData.theme.chat.message.outgoing.primaryTextColor, range: NSMakeRange(0, (toAttributedText.string as NSString).length))
self.toMessageTextNode.attributedText = toAttributedText
}
@@ -222,7 +229,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.messageClipNode.addSubnode(self.toMessageTextNode)
if let accessoryPanelNode = self.accessoryPanelNode {
self.messageClipNode.addSubnode(accessoryPanelNode)
self.addSubnode(accessoryPanelNode)
}
self.contentNodes.forEach(self.contentContainerNode.addSubnode)
@@ -332,7 +339,11 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.sendButtonNode.layer.animateScale(from: 0.75, to: 1.0, duration: 0.2, timingFunction: kCAMediaTimingFunctionLinear)
self.sendButtonNode.layer.animatePosition(from: self.sendButtonFrame.center, to: self.sendButtonNode.position, duration: duration, timingFunction: kCAMediaTimingFunctionSpring)
let initialWidth = self.textFieldFrame.width + 32.0
var initialWidth = self.textFieldFrame.width + 32.0
if self.textInputNode.textView.attributedText.string.isEmpty {
initialWidth = ceil(layout.size.width - self.textFieldFrame.origin.x - self.sendButtonFrame.width - layout.safeInsets.left - layout.safeInsets.right + 21.0)
}
let fromFrame = CGRect(origin: CGPoint(), size: CGSize(width: initialWidth, height: self.textFieldFrame.height + 2.0))
let delta = (fromFrame.height - self.messageClipNode.bounds.height) / 2.0
@@ -422,7 +433,11 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.sendButtonNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, timingFunction: kCAMediaTimingFunctionLinear, removeOnCompletion: false)
}
let initialWidth = self.textFieldFrame.width + 32.0
var initialWidth = self.textFieldFrame.width + 32.0
if self.textInputNode.textView.attributedText.string.isEmpty {
initialWidth = ceil(layout.size.width - self.textFieldFrame.origin.x - self.sendButtonFrame.width - layout.safeInsets.left - layout.safeInsets.right + 21.0)
}
let toFrame = CGRect(origin: CGPoint(), size: CGSize(width: initialWidth, height: self.textFieldFrame.height + 1.0))
let delta = (toFrame.height - self.messageClipNode.bounds.height) / 2.0
@@ -516,8 +531,12 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
messageFrame.origin.y += 60.0
}
if self.textInputNode.textView.numberOfLines == 1 {
let textWidth = min(self.textInputNode.textView.sizeThatFits(layout.size).width + 36.0, messageFrame.width)
if self.textInputNode.textView.attributedText.string.isEmpty {
messageFrame.size.width = ceil(layout.size.width - messageFrame.origin.x - sendButtonFrame.width - layout.safeInsets.left - layout.safeInsets.right + 8.0)
}
if self.textInputNode.textView.numberOfLines == 1 || self.textInputNode.textView.attributedText.string.isEmpty {
let textWidth = min(self.fromMessageTextNode.textView.sizeThatFits(layout.size).width + 36.0, messageFrame.width)
messageFrame.origin.x += messageFrame.width - textWidth
messageFrame.size.width = textWidth
}
@@ -544,6 +563,11 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
textFrame.size.height = self.textInputNode.textView.contentSize.height
self.fromMessageTextNode.frame = textFrame
self.toMessageTextNode.frame = textFrame
if let accessoryPanelNode = self.accessoryPanelNode {
let size = accessoryPanelNode.calculateSizeThatFits(CGSize(width: messageFrame.width, height: 45.0))
accessoryPanelNode.frame = CGRect(origin: CGPoint(x: 0.0, y: self.textFieldFrame.minY - size.height - 7.0), size: size)
}
}
@objc private func dimTapGesture(_ recognizer: UITapGestureRecognizer) {