Fix send button actions menu disappearance

This commit is contained in:
Ilya Laktyushin 2021-06-15 00:53:31 +03:00
parent aa2f80183f
commit 140d58bdd6
3 changed files with 22 additions and 32 deletions

View File

@ -6498,7 +6498,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let _ = ApplicationSpecificNotice.incrementChatMessageOptionsTip(accountManager: strongSelf.context.sharedContext.accountManager, count: 4).start() let _ = ApplicationSpecificNotice.incrementChatMessageOptionsTip(accountManager: strongSelf.context.sharedContext.accountManager, count: 4).start()
let controller = ChatSendMessageActionSheetController(context: strongSelf.context, controllerInteraction: strongSelf.controllerInteraction, interfaceState: strongSelf.presentationInterfaceState, gesture: gesture, sendButtonFrame: node.view.convert(node.bounds, to: nil), textInputNode: textInputNode, completion: { [weak self] in let controller = ChatSendMessageActionSheetController(context: strongSelf.context, controllerInteraction: strongSelf.controllerInteraction, interfaceState: strongSelf.presentationInterfaceState, gesture: gesture, sourceSendButton: node, textInputNode: textInputNode, completion: { [weak self] in
if let strongSelf = self { if let strongSelf = self {
strongSelf.supportedOrientations = previousSupportedOrientations strongSelf.supportedOrientations = previousSupportedOrientations
} }

View File

@ -17,7 +17,7 @@ final class ChatSendMessageActionSheetController: ViewController {
private let controllerInteraction: ChatControllerInteraction? private let controllerInteraction: ChatControllerInteraction?
private let interfaceState: ChatPresentationInterfaceState private let interfaceState: ChatPresentationInterfaceState
private let gesture: ContextGesture private let gesture: ContextGesture
private let sendButtonFrame: CGRect private let sourceSendButton: ASDisplayNode
private let textInputNode: EditableTextNode private let textInputNode: EditableTextNode
private let completion: () -> Void private let completion: () -> Void
@ -29,12 +29,12 @@ final class ChatSendMessageActionSheetController: ViewController {
private let hapticFeedback = HapticFeedback() private let hapticFeedback = HapticFeedback()
init(context: AccountContext, controllerInteraction: ChatControllerInteraction?, interfaceState: ChatPresentationInterfaceState, gesture: ContextGesture, sendButtonFrame: CGRect, textInputNode: EditableTextNode, completion: @escaping () -> Void) { init(context: AccountContext, controllerInteraction: ChatControllerInteraction?, interfaceState: ChatPresentationInterfaceState, gesture: ContextGesture, sourceSendButton: ASDisplayNode, textInputNode: EditableTextNode, completion: @escaping () -> Void) {
self.context = context self.context = context
self.controllerInteraction = controllerInteraction self.controllerInteraction = controllerInteraction
self.interfaceState = interfaceState self.interfaceState = interfaceState
self.gesture = gesture self.gesture = gesture
self.sendButtonFrame = sendButtonFrame self.sourceSendButton = sourceSendButton
self.textInputNode = textInputNode self.textInputNode = textInputNode
self.completion = completion self.completion = completion
@ -76,7 +76,7 @@ final class ChatSendMessageActionSheetController: ViewController {
canSchedule = !isSecret canSchedule = !isSecret
} }
self.displayNode = ChatSendMessageActionSheetControllerNode(context: self.context, reminders: reminders, gesture: gesture, sendButtonFrame: self.sendButtonFrame, textInputNode: self.textInputNode, forwardedCount: forwardedCount, send: { [weak self] in self.displayNode = ChatSendMessageActionSheetControllerNode(context: self.context, reminders: reminders, gesture: gesture, sourceSendButton: self.sourceSendButton, textInputNode: self.textInputNode, forwardedCount: forwardedCount, send: { [weak self] in
self?.controllerInteraction?.sendCurrentMessage(false) self?.controllerInteraction?.sendCurrentMessage(false)
self?.dismiss(cancel: false) self?.dismiss(cancel: false)
}, sendSilently: { [weak self] in }, sendSilently: { [weak self] in

View File

@ -154,7 +154,7 @@ private final class ActionSheetItemNode: ASDisplayNode {
final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, UIScrollViewDelegate { final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, UIScrollViewDelegate {
private let context: AccountContext private let context: AccountContext
private var presentationData: PresentationData private var presentationData: PresentationData
private let sendButtonFrame: CGRect private let sourceSendButton: ASDisplayNode
private let textFieldFrame: CGRect private let textFieldFrame: CGRect
private let textInputNode: EditableTextNode private let textInputNode: EditableTextNode
private let accessoryPanelNode: AccessoryPanelNode? private let accessoryPanelNode: AccessoryPanelNode?
@ -163,9 +163,6 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
private let send: (() -> Void)? private let send: (() -> Void)?
private let cancel: (() -> Void)? private let cancel: (() -> Void)?
private let textCoverNode: ASDisplayNode
private let buttonCoverNode: ASDisplayNode
private let effectView: UIVisualEffectView private let effectView: UIVisualEffectView
private let dimNode: ASDisplayNode private let dimNode: ASDisplayNode
@ -181,10 +178,14 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
private var validLayout: ContainerViewLayout? private var validLayout: ContainerViewLayout?
init(context: AccountContext, reminders: Bool, gesture: ContextGesture, sendButtonFrame: CGRect, textInputNode: EditableTextNode, forwardedCount: Int?, send: (() -> Void)?, sendSilently: (() -> Void)?, schedule: (() -> Void)?, cancel: (() -> Void)?) { private var sendButtonFrame: CGRect {
return self.sourceSendButton.view.convert(self.sourceSendButton.bounds, to: nil)
}
init(context: AccountContext, reminders: Bool, gesture: ContextGesture, sourceSendButton: ASDisplayNode, textInputNode: EditableTextNode, forwardedCount: Int?, send: (() -> Void)?, sendSilently: (() -> Void)?, schedule: (() -> Void)?, cancel: (() -> Void)?) {
self.context = context self.context = context
self.presentationData = context.sharedContext.currentPresentationData.with { $0 } self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
self.sendButtonFrame = sendButtonFrame self.sourceSendButton = sourceSendButton
self.textFieldFrame = textInputNode.convert(textInputNode.bounds, to: nil) self.textFieldFrame = textInputNode.convert(textInputNode.bounds, to: nil)
self.textInputNode = textInputNode self.textInputNode = textInputNode
self.accessoryPanelNode = nil self.accessoryPanelNode = nil
@ -192,10 +193,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.send = send self.send = send
self.cancel = cancel self.cancel = cancel
self.textCoverNode = ASDisplayNode()
self.buttonCoverNode = ASDisplayNode()
self.effectView = UIVisualEffectView() self.effectView = UIVisualEffectView()
if #available(iOS 9.0, *) { if #available(iOS 9.0, *) {
} else { } else {
@ -249,13 +247,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.contentNodes = contentNodes self.contentNodes = contentNodes
super.init() super.init()
self.textCoverNode.backgroundColor = self.presentationData.theme.chat.inputPanel.inputBackgroundColor
self.addSubnode(self.textCoverNode)
self.buttonCoverNode.backgroundColor = self.presentationData.theme.chat.inputPanel.panelBackgroundColor
self.addSubnode(self.buttonCoverNode)
self.sendButtonNode.setImage(PresentationResourcesChat.chatInputPanelSendButtonImage(self.presentationData.theme), for: []) self.sendButtonNode.setImage(PresentationResourcesChat.chatInputPanelSendButtonImage(self.presentationData.theme), for: [])
self.sendButtonNode.addTarget(self, action: #selector(sendButtonPressed), forControlEvents: .touchUpInside) self.sendButtonNode.addTarget(self, action: #selector(sendButtonPressed), forControlEvents: .touchUpInside)
@ -370,8 +362,6 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.dimNode.backgroundColor = presentationData.theme.contextMenu.dimColor self.dimNode.backgroundColor = presentationData.theme.contextMenu.dimColor
self.contentContainerNode.backgroundColor = self.presentationData.theme.contextMenu.backgroundColor self.contentContainerNode.backgroundColor = self.presentationData.theme.contextMenu.backgroundColor
self.textCoverNode.backgroundColor = self.presentationData.theme.chat.inputPanel.inputBackgroundColor
self.buttonCoverNode.backgroundColor = self.presentationData.theme.chat.inputPanel.panelBackgroundColor
self.sendButtonNode.setImage(PresentationResourcesChat.chatInputPanelSendButtonImage(self.presentationData.theme), for: []) self.sendButtonNode.setImage(PresentationResourcesChat.chatInputPanelSendButtonImage(self.presentationData.theme), for: [])
if let toAttributedText = self.textInputNode.attributedText?.mutableCopy() as? NSMutableAttributedString { if let toAttributedText = self.textInputNode.attributedText?.mutableCopy() as? NSMutableAttributedString {
@ -406,6 +396,9 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
self.fromMessageTextNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) self.fromMessageTextNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false)
self.toMessageTextNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3, removeOnCompletion: false) self.toMessageTextNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3, removeOnCompletion: false)
self.textInputNode.isHidden = true
self.sourceSendButton.isHidden = true
if let layout = self.validLayout { if let layout = self.validLayout {
let duration = 0.4 let duration = 0.4
@ -466,8 +459,8 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
let intermediateCompletion: () -> Void = { [weak self] in let intermediateCompletion: () -> Void = { [weak self] in
if completedEffect && completedButton && completedBubble && completedAlpha { if completedEffect && completedButton && completedBubble && completedAlpha {
self?.textCoverNode.isHidden = true self?.textInputNode.isHidden = false
self?.buttonCoverNode.isHidden = true self?.sourceSendButton.isHidden = false
completion() completion()
} }
} }
@ -494,7 +487,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
intermediateCompletion() intermediateCompletion()
}) })
} else { } else {
self.textCoverNode.isHidden = true self.textInputNode.isHidden = false
self.messageClipNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { _ in self.messageClipNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { _ in
completedAlpha = true completedAlpha = true
intermediateCompletion() intermediateCompletion()
@ -510,7 +503,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
}) })
if !cancel { if !cancel {
self.buttonCoverNode.isHidden = true self.sourceSendButton.isHidden = false
self.sendButtonNode.layer.animateScale(from: 1.0, to: 0.2, duration: 0.2, timingFunction: CAMediaTimingFunctionName.linear.rawValue, removeOnCompletion: false) self.sendButtonNode.layer.animateScale(from: 1.0, to: 0.2, duration: 0.2, timingFunction: CAMediaTimingFunctionName.linear.rawValue, removeOnCompletion: false)
self.sendButtonNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, timingFunction: CAMediaTimingFunctionName.linear.rawValue, removeOnCompletion: false) self.sendButtonNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, timingFunction: CAMediaTimingFunctionName.linear.rawValue, removeOnCompletion: false)
} }
@ -565,10 +558,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
self.validLayout = layout self.validLayout = layout
transition.updateFrame(node: self.textCoverNode, frame: self.textFieldFrame)
transition.updateFrame(node: self.buttonCoverNode, frame: self.sendButtonFrame.offsetBy(dx: 1.0, dy: 1.0))
transition.updateFrame(view: self.effectView, frame: CGRect(origin: CGPoint(), size: layout.size)) transition.updateFrame(view: self.effectView, frame: CGRect(origin: CGPoint(), size: layout.size))
transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(), size: layout.size)) transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(), size: layout.size))