From e54bb8c34a8d429ac0dfa1e6fa1b25e70e82c8e2 Mon Sep 17 00:00:00 2001 From: Peter Iakovlev Date: Sat, 24 Feb 2018 16:27:31 +0400 Subject: [PATCH] no message --- TelegramUI/ChatController.swift | 4 ++-- TelegramUI/ChatControllerNode.swift | 6 +++-- .../ChatMessageActionSheetController.swift | 4 ++++ ...ChatMessageActionSheetControllerNode.swift | 23 +++++++++++++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index b190fa3f19..657d2848da 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -315,12 +315,12 @@ public final class ChatController: TelegramController, UIViewControllerPreviewin } if !contextActions.isEmpty { - contextMenuController = ContextMenuController(actions: contextActions) + contextMenuController = ContextMenuController(actions: contextActions, catchTapsOutside: true) } contextMenuController?.dismissed = { if let strongSelf = self { - //strongSelf.chatDisplayNode.displayMessageActionSheet(stableId: nil, displayContextMenuController: nil) + strongSelf.chatDisplayNode.displayMessageActionSheet(stableId: nil, sheetActions: nil, displayContextMenuController: nil) } } diff --git a/TelegramUI/ChatControllerNode.swift b/TelegramUI/ChatControllerNode.swift index 214e5bd767..d4d89325dd 100644 --- a/TelegramUI/ChatControllerNode.swift +++ b/TelegramUI/ChatControllerNode.swift @@ -1339,7 +1339,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } } - let transition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .spring) + let transition: ContainedViewLayoutTransition = .animated(duration: 0.35, curve: .spring) var animateIn = false self.historyNode.updateNodeHighlightsAnimated(animated) @@ -1352,8 +1352,10 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { self.messageActionSheetControllerAdditionalInset = nil } if let stableId = self.controllerInteraction.contextHighlightedState?.messageStableId { - let controller = ChatMessageActionSheetController(theme: self.chatPresentationInterfaceState.theme, actions: sheetActions ?? [], dismissed: { [weak self] in + let contextMenuController = displayContextMenuController?.0 + let controller = ChatMessageActionSheetController(theme: self.chatPresentationInterfaceState.theme, actions: sheetActions ?? [], dismissed: { [weak self, weak contextMenuController] in self?.displayMessageActionSheet(stableId: nil, sheetActions: nil, displayContextMenuController: nil) + contextMenuController?.dismiss() }) self.messageActionSheetController = (controller, stableId) self.controllerInteraction.presentGlobalOverlayController(controller, nil) diff --git a/TelegramUI/ChatMessageActionSheetController.swift b/TelegramUI/ChatMessageActionSheetController.swift index f547ce4652..7ccccd6afb 100644 --- a/TelegramUI/ChatMessageActionSheetController.swift +++ b/TelegramUI/ChatMessageActionSheetController.swift @@ -27,4 +27,8 @@ final class ChatMessageActionSheetController: ViewController { self.displayNode = ChatMessageActionSheetControllerNode(theme: self.theme, actions: self.actions, dismissed: self.dismissed) self.displayNodeDidLoad() } + + override func dismiss(completion: (() -> Void)? = nil) { + self.presentingViewController?.dismiss(animated: false, completion: nil) + } } diff --git a/TelegramUI/ChatMessageActionSheetControllerNode.swift b/TelegramUI/ChatMessageActionSheetControllerNode.swift index 668ff3a8ae..3bd8bac4a6 100644 --- a/TelegramUI/ChatMessageActionSheetControllerNode.swift +++ b/TelegramUI/ChatMessageActionSheetControllerNode.swift @@ -60,6 +60,7 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { private let actionNodes: [MessageActionButtonNode] private let feedback = HapticFeedback() + private var validLayout: ContainerViewLayout? init(theme: PresentationTheme, actions: [ChatMessageContextMenuSheetAction], dismissed: @escaping () -> Void) { self.theme = theme @@ -68,7 +69,6 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { self.inputDimNode = ASDisplayNode() self.inputDimNode.backgroundColor = UIColor(white: 0.0, alpha: 0.5) - self.inputDimNode.isLayerBacked = true self.itemsContainerNode = ASDisplayNode() self.itemsContainerNode.backgroundColor = theme.actionSheet.opaqueItemBackgroundColor @@ -94,6 +94,12 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { self.feedback.prepareImpact() } + override func didLoad() { + super.didLoad() + + self.inputDimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTap(_:)))) + } + func animateIn(transition: ContainedViewLayoutTransition) { self.inputDimNode.alpha = 0.0 transition.updateAlpha(node: self.inputDimNode, alpha: 1.0) @@ -110,7 +116,9 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { } func updateLayout(layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) -> CGFloat { - var height: CGFloat = 14.0 + self.validLayout = layout + + var height: CGFloat = max(14.0, layout.intrinsicInsets.bottom) let inputHeight = layout.inputHeight ?? 0.0 transition.updateFrame(node: self.inputDimNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - inputHeight), size: CGSize(width: layout.size.width, height: inputHeight))) @@ -138,6 +146,11 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { let subpoint = self.view.convert(point, to: self.itemsContainerNode.view) return itemsContainerNode.hitTest(subpoint, with: event) } + if let validLayout = self.validLayout, let inputHeight = validLayout.inputHeight { + if point.y >= validLayout.size.height - inputHeight { + return self.inputDimNode.view + } + } return nil } @@ -150,4 +163,10 @@ final class ChatMessageActionSheetControllerNode: ViewControllerTracingNode { } } } + + @objc func dimTap(_ recognizer: UITapGestureRecognizer) { + if case .ended = recognizer.state { + self.dismissed() + } + } }