This commit is contained in:
Ali
2020-11-03 21:16:20 +04:00
parent a93646ea84
commit a79856582e
16 changed files with 521 additions and 285 deletions

View File

@@ -15,17 +15,33 @@ import TelegramStringFormatting
import AnimatedCountLabelNode
import AnimatedNavigationStripeNode
import ContextUI
import RadialStatusNode
private enum PinnedMessageAnimation {
case slideToTop
case slideToBottom
}
private final class ButtonsContainerNode: ASDisplayNode {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if let subnodes = self.subnodes {
for subnode in subnodes {
if let result = subnode.view.hitTest(self.view.convert(point, to: subnode.view), with: event) {
return result
}
}
}
return nil
}
}
final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
private let context: AccountContext
private let tapButton: HighlightTrackingButtonNode
private let buttonsContainer: ButtonsContainerNode
private let closeButton: HighlightableButtonNode
private let listButton: HighlightableButtonNode
private let activityIndicator: RadialStatusNode
private let contextContainer: ContextControllerSourceNode
private let clippingContainer: ASDisplayNode
@@ -47,6 +63,8 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
private var isReplyThread: Bool = false
private let fetchDisposable = MetaDisposable()
private var statusDisposable: Disposable?
private let queue = Queue()
@@ -55,6 +73,8 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
self.tapButton = HighlightTrackingButtonNode()
self.buttonsContainer = ButtonsContainerNode()
self.closeButton = HighlightableButtonNode()
self.closeButton.hitTestSlop = UIEdgeInsets(top: -8.0, left: -8.0, bottom: -8.0, right: -8.0)
self.closeButton.displaysAsynchronously = false
@@ -63,6 +83,9 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
self.listButton.hitTestSlop = UIEdgeInsets(top: -8.0, left: -8.0, bottom: -8.0, right: -8.0)
self.listButton.displaysAsynchronously = false
self.activityIndicator = RadialStatusNode(backgroundNodeColor: .clear)
self.activityIndicator.isUserInteractionEnabled = false
self.separatorNode = ASDisplayNode()
self.separatorNode.isLayerBacked = true
@@ -126,8 +149,9 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
self.imageNodeContainer.addSubnode(self.imageNode)
self.contentContainer.addSubnode(self.imageNodeContainer)
self.contextContainer.addSubnode(self.closeButton)
self.contextContainer.addSubnode(self.listButton)
self.buttonsContainer.addSubnode(self.closeButton)
self.buttonsContainer.addSubnode(self.listButton)
self.contextContainer.addSubnode(self.buttonsContainer)
self.tapButton.addTarget(self, action: #selector(self.tapped), forControlEvents: [.touchUpInside])
self.contextContainer.addSubnode(self.tapButton)
@@ -146,6 +170,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
deinit {
self.fetchDisposable.dispose()
self.statusDisposable?.dispose()
}
private var theme: PresentationTheme?
@@ -165,6 +190,35 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
self.separatorNode.backgroundColor = interfaceState.theme.chat.historyNavigation.strokeColor
}
if self.statusDisposable == nil, let interfaceInteraction = self.interfaceInteraction, let statuses = interfaceInteraction.statuses {
self.statusDisposable = (statuses.loadingMessage
|> map { status -> Bool in
return status == .pinnedMessage
}
|> deliverOnMainQueue).start(next: { [weak self] isLoading in
guard let strongSelf = self else {
return
}
if isLoading {
if strongSelf.activityIndicator.supernode == nil {
strongSelf.buttonsContainer.supernode?.insertSubnode(strongSelf.activityIndicator, aboveSubnode: strongSelf.buttonsContainer)
if let theme = strongSelf.theme {
strongSelf.activityIndicator.transitionToState(.progress(color: theme.chat.inputPanel.panelControlAccentColor, lineWidth: nil, value: nil, cancelEnabled: false), animated: false, completion: {
})
}
}
strongSelf.buttonsContainer.isHidden = true
} else {
if strongSelf.activityIndicator.supernode != nil {
strongSelf.activityIndicator.removeFromSupernode()
strongSelf.activityIndicator.transitionToState(.none, animated: false, completion: {
})
}
strongSelf.buttonsContainer.isHidden = false
}
})
}
let isReplyThread: Bool
if case .replyThread = interfaceState.chatLocation {
isReplyThread = true
@@ -219,12 +273,17 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
let rightInset: CGFloat = 18.0 + rightInset
self.buttonsContainer.frame = CGRect(origin: CGPoint(), size: CGSize(width: width, height: panelHeight))
let closeButtonSize = self.closeButton.measure(CGSize(width: 100.0, height: 100.0))
transition.updateFrame(node: self.closeButton, frame: CGRect(origin: CGPoint(x: width - rightInset - closeButtonSize.width, y: 19.0), size: closeButtonSize))
let listButtonSize = self.listButton.measure(CGSize(width: 100.0, height: 100.0))
transition.updateFrame(node: self.listButton, frame: CGRect(origin: CGPoint(x: width - rightInset - listButtonSize.width + 4.0, y: 13.0), size: listButtonSize))
let indicatorSize = CGSize(width: 22.0, height: 22.0)
transition.updateFrame(node: self.activityIndicator, frame: CGRect(origin: CGPoint(x: width - rightInset - indicatorSize.width + 2.0, y: 15.0), size: indicatorSize))
transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: panelHeight - UIScreenPixel), size: CGSize(width: width, height: UIScreenPixel)))
self.tapButton.frame = CGRect(origin: CGPoint(), size: CGSize(width: width - rightInset - closeButtonSize.width - 4.0, height: panelHeight))
@@ -450,7 +509,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
if self.isReplyThread {
interfaceInteraction.scrollToTop()
} else {
interfaceInteraction.navigateToMessage(message.message.id, false, true)
interfaceInteraction.navigateToMessage(message.message.id, false, true, .pinnedMessage)
}
}
}