Upgrade greeting sticker to new transition animation

This commit is contained in:
Ilya Laktyushin 2021-05-05 19:11:18 +04:00
parent f884d9586c
commit ff7fc4b142
11 changed files with 37 additions and 150 deletions

View File

@ -1050,7 +1050,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
replyPanel = accessoryPanelNode
}
if strongSelf.chatDisplayNode.shouldAnimateMessageTransition {
var shouldAnimateMessageTransition = strongSelf.chatDisplayNode.shouldAnimateMessageTransition
if sourceNode is ChatEmptyNodeStickerContentNode {
shouldAnimateMessageTransition = true
}
if shouldAnimateMessageTransition {
if let sourceNode = sourceNode as? ChatMediaInputStickerGridItemNode {
strongSelf.chatDisplayNode.messageTransitionNode.add(correlationId: correlationId, source: .stickerMediaInput(input: .inputPanel(itemNode: sourceNode), replyPanel: replyPanel), initiated: {
guard let strongSelf = self else {
@ -1072,6 +1076,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.chatDisplayNode.messageTransitionNode.add(correlationId: correlationId, source: .stickerMediaInput(input: .mediaPanel(itemNode: sourceNode), replyPanel: replyPanel), initiated: {})
} else if let sourceNode = sourceNode as? StickerPaneSearchStickerItemNode {
strongSelf.chatDisplayNode.messageTransitionNode.add(correlationId: correlationId, source: .stickerMediaInput(input: .inputPanelSearch(itemNode: sourceNode), replyPanel: replyPanel), initiated: {})
} else if let sourceNode = sourceNode as? ChatEmptyNodeStickerContentNode {
strongSelf.chatDisplayNode.messageTransitionNode.add(correlationId: correlationId, source: .stickerMediaInput(input: .emptyPanel(itemNode: sourceNode), replyPanel: nil), initiated: {})
}
}
@ -2492,8 +2498,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
if !onlyHaptic {
strongSelf.chatDisplayNode.animateQuizCorrectOptionSelected()
}
}, greetingStickerNode: { [weak self] in
return self?.chatDisplayNode.greetingStickerNode
}, openPeerContextMenu: { [weak self] peer, messageId, node, rect, gesture in
guard let strongSelf = self else {
return

View File

@ -114,7 +114,6 @@ public final class ChatControllerInteraction {
let displayPsa: (String, ASDisplayNode) -> Void
let displayDiceTooltip: (TelegramMediaDice) -> Void
let animateDiceSuccess: (Bool) -> Void
let greetingStickerNode: () -> (ASDisplayNode, ASDisplayNode, ASDisplayNode, (@escaping () -> Void) -> Void)?
let openPeerContextMenu: (Peer, MessageId?, ASDisplayNode, CGRect, ContextGesture?) -> Void
let openMessageReplies: (MessageId, Bool, Bool) -> Void
let openReplyThreadOriginalMessage: (Message) -> Void
@ -206,7 +205,6 @@ public final class ChatControllerInteraction {
displayPsa: @escaping (String, ASDisplayNode) -> Void,
displayDiceTooltip: @escaping (TelegramMediaDice) -> Void,
animateDiceSuccess: @escaping (Bool) -> Void,
greetingStickerNode: @escaping () -> (ASDisplayNode, ASDisplayNode, ASDisplayNode, (@escaping () -> Void) -> Void)?,
openPeerContextMenu: @escaping (Peer, MessageId?, ASDisplayNode, CGRect, ContextGesture?) -> Void,
openMessageReplies: @escaping (MessageId, Bool, Bool) -> Void,
openReplyThreadOriginalMessage: @escaping (Message) -> Void,
@ -285,7 +283,6 @@ public final class ChatControllerInteraction {
self.openMessagePollResults = openMessagePollResults
self.displayDiceTooltip = displayDiceTooltip
self.animateDiceSuccess = animateDiceSuccess
self.greetingStickerNode = greetingStickerNode
self.openPeerContextMenu = openPeerContextMenu
self.openMessageReplies = openMessageReplies
self.openReplyThreadOriginalMessage = openReplyThreadOriginalMessage
@ -338,8 +335,6 @@ public final class ChatControllerInteraction {
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in

View File

@ -792,23 +792,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
}
}
var greetingStickerNode: (ASDisplayNode, ASDisplayNode, ASDisplayNode, (@escaping () -> Void) -> Void)? {
if let greetingStickerNode = self.emptyNode?.greetingStickerNode {
let historyNode = self.historyNode
historyNode.alpha = 0.0
return (greetingStickerNode, self, self.historyNode, { completion in
historyNode.alpha = 1.0
historyNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, completion: { _ in
completion()
})
})
} else {
return nil
}
}
private var isInFocus: Bool = false
func inFocusUpdated(isInFocus: Bool) {
self.isInFocus = isInFocus

View File

@ -67,7 +67,11 @@ private final class ChatEmptyNodeRegularChatContent: ASDisplayNode, ChatEmptyNod
}
}
private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate {
protocol ChatEmptyNodeStickerContentNode: ASDisplayNode {
var stickerNode: ChatMediaInputStickerGridItemNode { get }
}
final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNodeStickerContentNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate {
private let context: AccountContext
private let interaction: ChatPanelInterfaceInteraction?
@ -75,24 +79,14 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo
private let textNode: ImmediateTextNode
private var stickerItem: ChatMediaInputStickerGridItem?
private let stickerNode: ChatMediaInputStickerGridItemNode
let stickerNode: ChatMediaInputStickerGridItemNode
private var currentTheme: PresentationTheme?
private var currentStrings: PresentationStrings?
private var didSetupSticker = false
private let disposable = MetaDisposable()
var greetingStickerNode: ASDisplayNode? {
if let animationNode = self.stickerNode.animationNode, animationNode.supernode === stickerNode {
return animationNode
} else if self.stickerNode.imageNode.supernode === stickerNode {
return self.stickerNode.imageNode
} else {
return nil
}
}
init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) {
self.context = context
self.interaction = interaction
@ -140,7 +134,7 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo
guard let stickerItem = self.stickerItem else {
return
}
let _ = self.interaction?.sendSticker(.standalone(media: stickerItem.stickerItem.file), self.stickerNode, self.stickerNode.bounds)
let _ = self.interaction?.sendSticker(.standalone(media: stickerItem.stickerItem.file), self, self.stickerNode.bounds)
}
func updateLayout(interfaceState: ChatPresentationInterfaceState, size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize {
@ -234,7 +228,7 @@ private final class ChatEmptyNodeGreetingChatContent: ASDisplayNode, ChatEmptyNo
}
}
private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate {
final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNodeStickerContentNode, ChatEmptyNodeContent, UIGestureRecognizerDelegate {
private let context: AccountContext
private let interaction: ChatPanelInterfaceInteraction?
@ -242,7 +236,7 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode
private let textNode: ImmediateTextNode
private var stickerItem: ChatMediaInputStickerGridItem?
private let stickerNode: ChatMediaInputStickerGridItemNode
let stickerNode: ChatMediaInputStickerGridItemNode
private var currentTheme: PresentationTheme?
private var currentStrings: PresentationStrings?
@ -250,16 +244,6 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode
private var didSetupSticker = false
private let disposable = MetaDisposable()
var greetingStickerNode: ASDisplayNode? {
if let animationNode = self.stickerNode.animationNode, animationNode.supernode === stickerNode {
return animationNode
} else if self.stickerNode.imageNode.supernode === stickerNode {
return self.stickerNode.imageNode
} else {
return nil
}
}
init(context: AccountContext, interaction: ChatPanelInterfaceInteraction?) {
self.context = context
self.interaction = interaction
@ -307,7 +291,7 @@ private final class ChatEmptyNodeNearbyChatContent: ASDisplayNode, ChatEmptyNode
guard let stickerItem = self.stickerItem else {
return
}
let _ = self.interaction?.sendSticker(.standalone(media: stickerItem.stickerItem.file), self.stickerNode, self.stickerNode.bounds)
let _ = self.interaction?.sendSticker(.standalone(media: stickerItem.stickerItem.file), self, self.stickerNode.bounds)
}
func updateLayout(interfaceState: ChatPresentationInterfaceState, size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize {
@ -908,17 +892,6 @@ final class ChatEmptyNode: ASDisplayNode {
transition.updateFrame(node: self.backgroundNode, frame: contentFrame)
}
var greetingStickerNode: ASDisplayNode? {
if let (_, node) = self.content {
if let node = node as? ChatEmptyNodeGreetingChatContent {
return node.greetingStickerNode
} else if let node = node as? ChatEmptyNodeNearbyChatContent {
return node.greetingStickerNode
}
}
return nil
}
}

View File

@ -160,12 +160,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
private(set) var animationNode: GenericAnimatedStickerNode?
private var didSetUpAnimationNode = false
private var isPlaying = false
private var animateGreeting = false
private var animatingGreeting = false
private weak var greetingStickerParentNode: ASDisplayNode?
private weak var greetingStickerListNode: ASDisplayNode?
private var greetingCompletion: ((@escaping () -> Void) -> Void)?
private var swipeToReplyNode: ChatMessageSwipeToReplyNode?
private var swipeToReplyFeedback: HapticFeedback?
@ -261,7 +256,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
return
}
if image != nil {
if firstTime && !strongSelf.placeholderNode.isEmpty && !strongSelf.animateGreeting && !strongSelf.animatingGreeting {
if firstTime && !strongSelf.placeholderNode.isEmpty {
if strongSelf.enableSynchronousImageApply {
strongSelf.removePlaceholder(animated: false)
} else {
@ -422,33 +417,22 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
self.animationNode = animationNode
}
} else {
let animationNode: AnimatedStickerNode
if let (node, parentNode, listNode, greetingCompletion) = item.controllerInteraction.greetingStickerNode(), let greetingStickerNode = node as? AnimatedStickerNode {
animationNode = greetingStickerNode
self.imageNode.alpha = 0.0
self.animateGreeting = true
self.greetingStickerParentNode = parentNode
self.greetingStickerListNode = listNode
self.greetingCompletion = greetingCompletion
} else {
animationNode = AnimatedStickerNode()
animationNode.started = { [weak self] in
if let strongSelf = self {
strongSelf.imageNode.alpha = 0.0
if let item = strongSelf.item {
if let _ = strongSelf.emojiFile {
item.controllerInteraction.seenOneTimeAnimatedMedia.insert(item.message.id)
}
let animationNode = AnimatedStickerNode()
animationNode.started = { [weak self] in
if let strongSelf = self {
strongSelf.imageNode.alpha = 0.0
if let item = strongSelf.item {
if let _ = strongSelf.emojiFile {
item.controllerInteraction.seenOneTimeAnimatedMedia.insert(item.message.id)
}
}
}
}
self.animationNode = animationNode
}
if let animationNode = self.animationNode, !self.animateGreeting {
if let animationNode = self.animationNode {
self.contextSourceNode.contentNode.insertSubnode(animationNode, aboveSubnode: self.placeholderNode)
}
}
@ -1025,53 +1009,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
strongSelf.placeholderNode.frame = animationNodeFrame
}
if let animationNode = strongSelf.animationNode, let parentNode = strongSelf.greetingStickerParentNode, strongSelf.animateGreeting {
strongSelf.animateGreeting = false
strongSelf.animatingGreeting = true
let initialFrame = animationNode.view.convert(animationNode.bounds, to: parentNode.view)
parentNode.addSubnode(animationNode)
animationNode.frame = initialFrame
var targetPositionY = initialFrame.center.y
if let listNode = strongSelf.greetingStickerListNode as? ListView {
targetPositionY = listNode.frame.height - listNode.insets.top - animationNodeFrame.height / 2.0 - 12.0
}
let targetPosition = CGPoint(x: animationNodeFrame.midX, y: targetPositionY)
let targetScale = animationNodeFrame.width / initialFrame.width
animationNode.layer.animateScale(from: 1.0, to: targetScale, duration: 0.3, removeOnCompletion: false)
animationNode.layer.animatePosition(from: initialFrame.center, to: targetPosition, duration: 0.4, mediaTimingFunction: CAMediaTimingFunction(controlPoints: 0.3, 0.0, 0.0, 1.0), removeOnCompletion: false, completion: { [weak self] finished in
if let strongSelf = self {
let initialDateNodeFrame = strongSelf.dateAndStatusNode.frame
if strongSelf.animatingGreeting {
if strongSelf.dateAndStatusNode.supernode !== parentNode {
let dateNodeFrame = strongSelf.dateAndStatusNode.view.convert(strongSelf.dateAndStatusNode.bounds, to: parentNode.view)
parentNode.addSubnode(strongSelf.dateAndStatusNode)
strongSelf.dateAndStatusNode.frame = dateNodeFrame
strongSelf.dateAndStatusNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
}
}
strongSelf.greetingCompletion?({
animationNode.layer.removeAllAnimations()
strongSelf.animationNode?.frame = animationNodeFrame
strongSelf.contextSourceNode.contentNode.insertSubnode(animationNode, aboveSubnode: strongSelf.imageNode)
strongSelf.contextSourceNode.contentNode.addSubnode(strongSelf.dateAndStatusNode)
strongSelf.dateAndStatusNode.frame = initialDateNodeFrame
if let animationNode = strongSelf.animationNode as? AnimatedStickerNode {
animationNode.updateLayout(size: updatedContentFrame.insetBy(dx: imageInset, dy: imageInset).size)
}
strongSelf.animatingGreeting = false
})
}
})
} else if strongSelf.animationNode?.supernode === strongSelf.contextSourceNode.contentNode {
if strongSelf.animationNode?.supernode === strongSelf.contextSourceNode.contentNode {
strongSelf.animationNode?.frame = animationNodeFrame
}
if let animationNode = strongSelf.animationNode as? AnimatedStickerNode, strongSelf.animationNode?.supernode === strongSelf.contextSourceNode.contentNode {
@ -1102,10 +1040,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
}
dateAndStatusApply(false)
let dateAndStatusFrame = CGRect(origin: CGPoint(x: max(displayLeftInset, updatedImageFrame.maxX - dateAndStatusSize.width - 4.0), y: updatedImageFrame.maxY - dateAndStatusSize.height - 4.0), size: dateAndStatusSize)
if strongSelf.dateAndStatusNode.supernode != strongSelf.greetingStickerParentNode {
strongSelf.dateAndStatusNode.frame = dateAndStatusFrame
}
strongSelf.dateAndStatusNode.frame = CGRect(origin: CGPoint(x: max(displayLeftInset, updatedImageFrame.maxX - dateAndStatusSize.width - 4.0), y: updatedImageFrame.maxY - dateAndStatusSize.height - 4.0), size: dateAndStatusSize)
if let updatedReplyBackgroundNode = updatedReplyBackgroundNode {
if strongSelf.replyBackgroundNode == nil {

View File

@ -129,6 +129,7 @@ final class ChatMessageTransitionNode: ASDisplayNode {
case inputPanel(itemNode: ChatMediaInputStickerGridItemNode)
case mediaPanel(itemNode: HorizontalStickerGridItemNode)
case inputPanelSearch(itemNode: StickerPaneSearchStickerItemNode)
case emptyPanel(itemNode: ChatEmptyNodeStickerContentNode)
}
final class AudioMicInput {
@ -299,6 +300,9 @@ final class ChatMessageTransitionNode: ASDisplayNode {
case let .inputPanelSearch(sourceItemNode):
stickerSource = Sticker(imageNode: sourceItemNode.imageNode, animationNode: sourceItemNode.animationNode, placeholderNode: nil, relativeSourceRect: sourceItemNode.imageNode.frame)
sourceAbsoluteRect = sourceItemNode.view.convert(stickerSource.imageNode.frame, to: nil)
case let .emptyPanel(sourceItemNode):
stickerSource = Sticker(imageNode: sourceItemNode.stickerNode.imageNode, animationNode: sourceItemNode.stickerNode.animationNode, placeholderNode: nil, relativeSourceRect: sourceItemNode.stickerNode.imageNode.frame)
sourceAbsoluteRect = sourceItemNode.stickerNode.view.convert(sourceItemNode.stickerNode.imageNode.frame, to: nil)
}
let targetAbsoluteRect = self.contextSourceNode.view.convert(self.contextSourceNode.contentRect, to: nil)
@ -348,6 +352,8 @@ final class ChatMessageTransitionNode: ASDisplayNode {
sourceItemNode.isHidden = true
case let .inputPanelSearch(sourceItemNode):
sourceItemNode.isHidden = true
case let .emptyPanel(sourceItemNode):
sourceItemNode.isHidden = true
}
case let .audioMicInput(audioMicInput):
if let (container, localRect) = audioMicInput.micButton.contentContainer {

View File

@ -528,8 +528,6 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in

View File

@ -145,8 +145,6 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode {
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in

View File

@ -137,8 +137,6 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in

View File

@ -2152,8 +2152,6 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in

View File

@ -1264,8 +1264,6 @@ public final class SharedAccountContextImpl: SharedAccountContext {
}, displayPsa: { _, _ in
}, displayDiceTooltip: { _ in
}, animateDiceSuccess: { _ in
}, greetingStickerNode: {
return nil
}, openPeerContextMenu: { _, _, _, _, _ in
}, openMessageReplies: { _, _, _ in
}, openReplyThreadOriginalMessage: { _ in