mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Clean up
This commit is contained in:
parent
78a463a6d2
commit
d7694f997c
@ -384,12 +384,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
var dismissAsOverlay: () -> Void = { }
|
var dismissAsOverlay: () -> Void = { }
|
||||||
|
|
||||||
var interfaceInteraction: ChatPanelInterfaceInteraction?
|
var interfaceInteraction: ChatPanelInterfaceInteraction?
|
||||||
|
|
||||||
private var messageActionSheetController: (ChatMessageActionSheetController, UInt32)?
|
|
||||||
private var messageActionSheetControllerAdditionalInset: CGFloat?
|
|
||||||
private var messageActionSheetTopDimNode: ASDisplayNode?
|
|
||||||
private var messageActionSheetBottomDimNode: ASDisplayNode?
|
|
||||||
|
|
||||||
private var expandedInputDimNode: ASDisplayNode?
|
private var expandedInputDimNode: ASDisplayNode?
|
||||||
|
|
||||||
private var dropDimNode: ASDisplayNode?
|
private var dropDimNode: ASDisplayNode?
|
||||||
@ -1406,42 +1401,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var displayTopDimNode = false
|
var displayTopDimNode = false
|
||||||
|
|
||||||
var ensureTopInsetForOverlayHighlightedItems: CGFloat?
|
var ensureTopInsetForOverlayHighlightedItems: CGFloat?
|
||||||
if let (controller, _) = self.messageActionSheetController {
|
|
||||||
displayTopDimNode = true
|
|
||||||
|
|
||||||
let globalSelfOrigin = self.view.convert(CGPoint(), to: nil)
|
|
||||||
|
|
||||||
let menuHeight = controller.controllerNode.updateLayout(layout: layout, horizontalOrigin: globalSelfOrigin.x, transition: transition)
|
|
||||||
ensureTopInsetForOverlayHighlightedItems = menuHeight
|
|
||||||
|
|
||||||
let bottomInset = containerInsets.bottom + inputPanelsHeight
|
|
||||||
let bottomFrame = CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - bottomInset), size: CGSize(width: layout.size.width, height: max(0.0, bottomInset - (layout.inputHeight ?? 0.0))))
|
|
||||||
|
|
||||||
let messageActionSheetBottomDimNode: ASDisplayNode
|
|
||||||
if let current = self.messageActionSheetBottomDimNode {
|
|
||||||
messageActionSheetBottomDimNode = current
|
|
||||||
transition.updateFrame(node: messageActionSheetBottomDimNode, frame: bottomFrame)
|
|
||||||
} else {
|
|
||||||
messageActionSheetBottomDimNode = ASDisplayNode()
|
|
||||||
messageActionSheetBottomDimNode.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
|
|
||||||
messageActionSheetBottomDimNode.alpha = 0.0
|
|
||||||
messageActionSheetBottomDimNode.isLayerBacked = true
|
|
||||||
self.messageActionSheetBottomDimNode = messageActionSheetBottomDimNode
|
|
||||||
self.addSubnode(messageActionSheetBottomDimNode)
|
|
||||||
transition.updateAlpha(node: messageActionSheetBottomDimNode, alpha: 1.0)
|
|
||||||
messageActionSheetBottomDimNode.frame = bottomFrame
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let messageActionSheetBottomDimNode = self.messageActionSheetBottomDimNode {
|
|
||||||
self.messageActionSheetBottomDimNode = nil
|
|
||||||
transition.updateAlpha(node: messageActionSheetBottomDimNode, alpha: 0.0, completion: { [weak messageActionSheetBottomDimNode] _ in
|
|
||||||
messageActionSheetBottomDimNode?.removeFromSupernode()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var expandTopDimNode = false
|
var expandTopDimNode = false
|
||||||
if case let .media(_, expanded) = self.chatPresentationInterfaceState.inputMode, expanded != nil {
|
if case let .media(_, expanded) = self.chatPresentationInterfaceState.inputMode, expanded != nil {
|
||||||
displayTopDimNode = true
|
displayTopDimNode = true
|
||||||
@ -1459,21 +1419,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
let topFrame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: max(0.0, topInset)))
|
let topFrame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: max(0.0, topInset)))
|
||||||
|
|
||||||
let messageActionSheetTopDimNode: ASDisplayNode
|
|
||||||
if let current = self.messageActionSheetTopDimNode {
|
|
||||||
messageActionSheetTopDimNode = current
|
|
||||||
transition.updateFrame(node: messageActionSheetTopDimNode, frame: topFrame)
|
|
||||||
} else {
|
|
||||||
messageActionSheetTopDimNode = ASDisplayNode()
|
|
||||||
messageActionSheetTopDimNode.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
|
|
||||||
messageActionSheetTopDimNode.alpha = 0.0
|
|
||||||
self.messageActionSheetTopDimNode = messageActionSheetTopDimNode
|
|
||||||
self.addSubnode(messageActionSheetTopDimNode)
|
|
||||||
transition.updateAlpha(node: messageActionSheetTopDimNode, alpha: 1.0)
|
|
||||||
messageActionSheetTopDimNode.frame = topFrame
|
|
||||||
messageActionSheetTopDimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.topDimNodeTapGesture(_:))))
|
|
||||||
}
|
|
||||||
|
|
||||||
let inputPanelOrigin = layout.size.height - insets.bottom - bottomOverflowOffset - inputPanelsHeight
|
let inputPanelOrigin = layout.size.height - insets.bottom - bottomOverflowOffset - inputPanelsHeight
|
||||||
|
|
||||||
if expandTopDimNode {
|
if expandTopDimNode {
|
||||||
@ -1506,13 +1451,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let messageActionSheetTopDimNode = self.messageActionSheetTopDimNode {
|
|
||||||
self.messageActionSheetTopDimNode = nil
|
|
||||||
transition.updateAlpha(node: messageActionSheetTopDimNode, alpha: 0.0, completion: { [weak messageActionSheetTopDimNode] _ in
|
|
||||||
messageActionSheetTopDimNode?.removeFromSupernode()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if let expandedInputDimNode = self.expandedInputDimNode {
|
if let expandedInputDimNode = self.expandedInputDimNode {
|
||||||
self.expandedInputDimNode = nil
|
self.expandedInputDimNode = nil
|
||||||
let inputPanelOrigin = layout.size.height - insets.bottom - bottomOverflowOffset - inputPanelsHeight
|
let inputPanelOrigin = layout.size.height - insets.bottom - bottomOverflowOffset - inputPanelsHeight
|
||||||
@ -1524,10 +1462,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let messageActionSheetControllerAdditionalInset = self.messageActionSheetControllerAdditionalInset {
|
|
||||||
listInsets.top = listInsets.top + messageActionSheetControllerAdditionalInset
|
|
||||||
}
|
|
||||||
|
|
||||||
var childrenLayout = layout
|
var childrenLayout = layout
|
||||||
childrenLayout.intrinsicInsets = UIEdgeInsets(top: listInsets.bottom, left: listInsets.right, bottom: listInsets.top, right: listInsets.left)
|
childrenLayout.intrinsicInsets = UIEdgeInsets(top: listInsets.bottom, left: listInsets.right, bottom: listInsets.top, right: listInsets.left)
|
||||||
self.controller?.presentationContext.containerLayoutUpdated(childrenLayout, transition: transition)
|
self.controller?.presentationContext.containerLayoutUpdated(childrenLayout, transition: transition)
|
||||||
@ -2390,121 +2324,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayMessageActionSheet(stableId: UInt32?, sheetActions: [ChatMessageContextMenuSheetAction]?, displayContextMenuController: (ContextMenuController, ASDisplayNode, CGRect)?) {
|
|
||||||
self.controllerInteraction.contextHighlightedState = stableId.flatMap { ChatInterfaceHighlightedState(messageStableId: $0) }
|
|
||||||
self.updateItemNodesContextHighlightedStates(animated: true, sheetActions: sheetActions, displayContextMenuController: displayContextMenuController)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func updateItemNodesContextHighlightedStates(animated: Bool, sheetActions: [ChatMessageContextMenuSheetAction]?, displayContextMenuController: (ContextMenuController, ASDisplayNode, CGRect)?) {
|
|
||||||
self.historyNode.forEachItemNode { itemNode in
|
|
||||||
if let itemNode = itemNode as? ChatMessageItemView {
|
|
||||||
itemNode.updateHighlightedState(animated: animated)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.35, curve: .spring)
|
|
||||||
var animateIn = false
|
|
||||||
|
|
||||||
self.historyNode.updateNodeHighlightsAnimated(animated)
|
|
||||||
if self.messageActionSheetController?.1 != self.controllerInteraction.contextHighlightedState?.messageStableId {
|
|
||||||
if let (controller, _) = self.messageActionSheetController {
|
|
||||||
controller.controllerNode.animateOut(transition: transition, completion: { [weak controller] in
|
|
||||||
controller?.dismiss()
|
|
||||||
})
|
|
||||||
self.messageActionSheetController = nil
|
|
||||||
self.messageActionSheetControllerAdditionalInset = nil
|
|
||||||
self.accessibilityElementsHidden = false
|
|
||||||
}
|
|
||||||
if let stableId = self.controllerInteraction.contextHighlightedState?.messageStableId {
|
|
||||||
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()
|
|
||||||
}, associatedController: contextMenuController)
|
|
||||||
self.messageActionSheetController = (controller, stableId)
|
|
||||||
self.accessibilityElementsHidden = true
|
|
||||||
if let sheetActions = sheetActions, !sheetActions.isEmpty, let (layout, _) = self.validLayout {
|
|
||||||
var isSlideOver = false
|
|
||||||
if case .compact = layout.metrics.widthClass, case .regular = layout.metrics.heightClass {
|
|
||||||
isSlideOver = true
|
|
||||||
}
|
|
||||||
if isSlideOver {
|
|
||||||
self.controllerInteraction.presentController(controller, nil)
|
|
||||||
} else {
|
|
||||||
self.controllerInteraction.presentGlobalOverlayController(controller, nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
animateIn = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let (layout, navigationBarHeight) = self.validLayout {
|
|
||||||
let globalSelfOrigin = self.view.convert(CGPoint(), to: nil)
|
|
||||||
let menuHeight = self.messageActionSheetController?.0.controllerNode.updateLayout(layout: layout, horizontalOrigin: globalSelfOrigin.x, transition: .immediate)
|
|
||||||
if let stableId = self.messageActionSheetController?.1 {
|
|
||||||
var resultItemNode: ListViewItemNode?
|
|
||||||
var resultItemSubnode: ASDisplayNode?
|
|
||||||
self.historyNode.forEachItemNode { itemNode in
|
|
||||||
if let itemNode = itemNode as? ChatMessageItemView, let item = itemNode.item {
|
|
||||||
switch item.content {
|
|
||||||
case let .message(message, _, _, _):
|
|
||||||
if message.stableId == stableId {
|
|
||||||
resultItemNode = itemNode
|
|
||||||
}
|
|
||||||
case let .group(messages):
|
|
||||||
for (message, _, _, _) in messages {
|
|
||||||
if message.stableId == stableId {
|
|
||||||
resultItemNode = itemNode
|
|
||||||
if let media = message.media.first {
|
|
||||||
resultItemSubnode = itemNode.transitionNode(id: message.id, media: media)?.0
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let resultItemNode = resultItemNode, let menuHeight = menuHeight {
|
|
||||||
var resultItemFrame = resultItemNode.frame
|
|
||||||
if let resultItemSubnode = resultItemSubnode {
|
|
||||||
resultItemFrame = resultItemSubnode.view.convert(resultItemSubnode.bounds, to: resultItemNode.view.superview)
|
|
||||||
}
|
|
||||||
if resultItemFrame.size.height < self.historyNode.bounds.size.height - self.historyNode.insets.top - self.historyNode.insets.bottom {
|
|
||||||
if resultItemFrame.minY < menuHeight {
|
|
||||||
messageActionSheetControllerAdditionalInset = menuHeight - resultItemFrame.minY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition, listViewTransaction: { updateSizeAndInsets, additionalScrollDistance, scrollToTop, completion in
|
|
||||||
self.historyNode.updateLayout(transition: transition, updateSizeAndInsets: updateSizeAndInsets, additionalScrollDistance: additionalScrollDistance, scrollToTop: scrollToTop, completion: completion)
|
|
||||||
})
|
|
||||||
if animateIn, let controller = self.messageActionSheetController?.0 {
|
|
||||||
controller.controllerNode.animateIn(transition: transition)
|
|
||||||
}
|
|
||||||
if let menuHeight = menuHeight {
|
|
||||||
if let _ = self.controllerInteraction.contextHighlightedState?.messageStableId, let (menuController, node, frame) = displayContextMenuController {
|
|
||||||
self.controllerInteraction.presentController(menuController, ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
|
||||||
if let strongSelf = self {
|
|
||||||
var bounds = strongSelf.bounds
|
|
||||||
bounds.size.height -= menuHeight
|
|
||||||
return (node, frame, strongSelf, bounds)
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||||
if let _ = self.messageActionSheetController {
|
|
||||||
self.displayMessageActionSheet(stableId: nil, sheetActions: nil, displayContextMenuController: nil)
|
|
||||||
return self.navigationBar?.view
|
|
||||||
}
|
|
||||||
|
|
||||||
switch self.chatPresentationInterfaceState.mode {
|
switch self.chatPresentationInterfaceState.mode {
|
||||||
case .standard(previewing: true):
|
case .standard(previewing: true):
|
||||||
if let result = self.navigateButtons.hitTest(self.view.convert(point, to: self.navigateButtons.view), with: event) {
|
if let result = self.navigateButtons.hitTest(self.view.convert(point, to: self.navigateButtons.view), with: event) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user