From ccd30832ccb2e773c19f5332afdcf3c887c61ed5 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 29 Aug 2021 13:27:02 +0300 Subject: [PATCH] Various Fixes --- .../ContextUI/Sources/ContextController.swift | 13 ++++++++-- .../TelegramUI/Sources/ChatController.swift | 2 +- .../Sources/ChatHistoryListNode.swift | 2 +- .../ChatMessageAnimatedStickerItemNode.swift | 23 ++++++++++++++++-- .../ChatMessageInstantVideoItemNode.swift | 24 +++++++++++++++---- .../Sources/ChatMessageStickerItemNode.swift | 23 ++++++++++++++++-- .../Sources/ForwardAccessoryPanelNode.swift | 6 +++++ .../Sources/MediaInputPaneTrendingItem.swift | 13 +++++----- 8 files changed, 88 insertions(+), 18 deletions(-) diff --git a/submodules/ContextUI/Sources/ContextController.swift b/submodules/ContextUI/Sources/ContextController.swift index 907df33043..53111d78d3 100644 --- a/submodules/ContextUI/Sources/ContextController.swift +++ b/submodules/ContextUI/Sources/ContextController.swift @@ -159,6 +159,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi private let hapticFeedback = HapticFeedback() + private var animatedIn = false private var isAnimatingOut = false private let itemsDisposable = MetaDisposable() @@ -479,6 +480,9 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } @objc private func dimNodeTapped() { + guard self.animatedIn else { + return + } self.dismissedForCancel?() self.beginDismiss(.default) } @@ -652,7 +656,9 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi self.actionsContainerNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: localSourceFrame.center.x - self.actionsContainerNode.position.x, y: localSourceFrame.center.y - self.actionsContainerNode.position.y)), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) let contentContainerOffset = CGPoint(x: localContentSourceFrame.center.x - self.contentContainerNode.frame.center.x, y: localContentSourceFrame.center.y - self.contentContainerNode.frame.center.y) - self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) + self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true, completion: { [weak self] _ in + self?.animatedIn = true + }) } case let .extracted(extracted, keepInPlace): let springDuration: Double = 0.42 * animationDurationFactor @@ -692,6 +698,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi let contentContainerOffset = CGPoint(x: localContentSourceFrame.center.x - self.contentContainerNode.frame.center.x - contentParentNode.contentRect.minX, y: localContentSourceFrame.center.y - self.contentContainerNode.frame.center.y - contentParentNode.contentRect.minY) self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: contentDuration, initialVelocity: 0.0, damping: springDamping, additive: true, completion: { [weak self] _ in self?.clippingNode.view.mask = nil + self?.animatedIn = true }) contentParentNode.applyAbsoluteOffsetSpring?(-contentContainerOffset.y, springDuration, springDamping) } @@ -735,7 +742,9 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi } } self.actionsContainerNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: localSourceFrame.center.x - self.actionsContainerNode.position.x, y: localSourceFrame.center.y - self.actionsContainerNode.position.y)), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) - self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true) + self.contentContainerNode.layer.animateSpring(from: NSValue(cgPoint: contentContainerOffset), to: NSValue(cgPoint: CGPoint()), keyPath: "position", duration: springDuration, initialVelocity: 0.0, damping: springDamping, additive: true, completion: { [weak self] _ in + self?.animatedIn = true + }) } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 60d5b52646..b0293dc2e2 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -5638,7 +5638,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: sourceNode, passthroughTouches: true)), items: items, reactionItems: []) - contextController.dismissedForCancel = { [weak self, weak chatController] in + contextController.dismissedForCancel = { [weak chatController] in if let selectedMessageIds = (chatController as? ChatControllerImpl)?.selectedMessageIds { var forwardMessageIds = strongSelf.presentationInterfaceState.interfaceState.forwardMessageIds ?? [] forwardMessageIds = forwardMessageIds.filter { selectedMessageIds.contains($0) } diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 8ed486740c..01e9c3532f 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -726,7 +726,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { scrollPosition = nil } - return (ChatHistoryViewUpdate.HistoryView(view: MessageHistoryView(tagMask: nil, namespaces: .all, entries: messages.reversed().map { MessageHistoryEntry(message: $0, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)) }, holeEarlier: hasMore, holeLater: false, isLoading: false), type: .Generic(type: ViewUpdateType.Initial), scrollPosition: scrollPosition, flashIndicators: false, originalScrollPosition: nil, initialData: ChatHistoryCombinedInitialData(initialData: nil, buttonKeyboardMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil), id: 0), version, nil) + return (ChatHistoryViewUpdate.HistoryView(view: MessageHistoryView(tagMask: nil, namespaces: .all, entries: messages.reversed().map { MessageHistoryEntry(message: $0, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)) }, holeEarlier: hasMore, holeLater: false, isLoading: false), type: .Generic(type: version > 0 ? ViewUpdateType.Generic : ViewUpdateType.Initial), scrollPosition: scrollPosition, flashIndicators: false, originalScrollPosition: nil, initialData: ChatHistoryCombinedInitialData(initialData: nil, buttonKeyboardMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil), id: 0), version, nil) } } else { historyViewUpdate = self.chatHistoryLocationPromise.get() diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index c3371c47dc..dc88df58f5 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -1166,6 +1166,16 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { strongSelf.forwardBackgroundNode = forwardBackgroundNode strongSelf.contextSourceNode.contentNode.addSubnode(forwardBackgroundNode) } + } else if let forwardBackgroundNode = strongSelf.forwardBackgroundNode { + if animation.isAnimated { + strongSelf.forwardBackgroundNode = nil + forwardBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardBackgroundNode] _ in + forwardBackgroundNode?.removeFromSupernode() + }) + } else { + forwardBackgroundNode.removeFromSupernode() + strongSelf.forwardBackgroundNode = nil + } } if let (forwardInfoSize, forwardInfoApply) = forwardInfoSizeApply { @@ -1181,8 +1191,17 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { forwardBackgroundNode.update(size: forwardBackgroundNode.bounds.size, cornerRadius: 8.0, transition: .immediate) } } else if let forwardInfoNode = strongSelf.forwardInfoNode { - forwardInfoNode.removeFromSupernode() - strongSelf.forwardInfoNode = nil + if animation.isAnimated { + if let forwardInfoNode = strongSelf.forwardInfoNode { + strongSelf.forwardInfoNode = nil + forwardInfoNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardInfoNode] _ in + forwardInfoNode?.removeFromSupernode() + }) + } + } else { + forwardInfoNode.removeFromSupernode() + strongSelf.forwardInfoNode = nil + } } if let actionButtonsSizeAndApply = actionButtonsSizeAndApply { diff --git a/submodules/TelegramUI/Sources/ChatMessageInstantVideoItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageInstantVideoItemNode.swift index 8f96ccbaf6..8471bebded 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInstantVideoItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInstantVideoItemNode.swift @@ -696,8 +696,15 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView, UIGestureRecognizerD strongSelf.contextSourceNode.contentNode.addSubnode(updatedForwardBackgroundNode) } } else if let forwardBackgroundNode = strongSelf.forwardBackgroundNode { - forwardBackgroundNode.removeFromSupernode() - strongSelf.forwardBackgroundNode = nil + if animation.isAnimated { + strongSelf.forwardBackgroundNode = nil + forwardBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardBackgroundNode] _ in + forwardBackgroundNode?.removeFromSupernode() + }) + } else { + forwardBackgroundNode.removeFromSupernode() + strongSelf.forwardBackgroundNode = nil + } } if let (forwardInfoSize, forwardInfoApply) = forwardInfoSizeApply { @@ -718,8 +725,17 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView, UIGestureRecognizerD strongSelf.forwardBackgroundNode?.frame = forwardBackgroundFrame strongSelf.forwardBackgroundNode?.update(size: forwardBackgroundFrame.size, cornerRadius: 8.0, transition: .immediate) } else if let forwardInfoNode = strongSelf.forwardInfoNode { - forwardInfoNode.removeFromSupernode() - strongSelf.forwardInfoNode = nil + if animation.isAnimated { + if let forwardInfoNode = strongSelf.forwardInfoNode { + strongSelf.forwardInfoNode = nil + forwardInfoNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardInfoNode] _ in + forwardInfoNode?.removeFromSupernode() + }) + } + } else { + forwardInfoNode.removeFromSupernode() + strongSelf.forwardInfoNode = nil + } } if let actionButtonsSizeAndApply = actionButtonsSizeAndApply { diff --git a/submodules/TelegramUI/Sources/ChatMessageStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageStickerItemNode.swift index 73e762b806..a04e934204 100644 --- a/submodules/TelegramUI/Sources/ChatMessageStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageStickerItemNode.swift @@ -854,6 +854,16 @@ class ChatMessageStickerItemNode: ChatMessageItemView { strongSelf.forwardBackgroundNode = forwardBackgroundNode strongSelf.contextSourceNode.contentNode.addSubnode(forwardBackgroundNode) } + } else if let forwardBackgroundNode = strongSelf.forwardBackgroundNode { + if animation.isAnimated { + strongSelf.forwardBackgroundNode = nil + forwardBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardBackgroundNode] _ in + forwardBackgroundNode?.removeFromSupernode() + }) + } else { + forwardBackgroundNode.removeFromSupernode() + strongSelf.forwardBackgroundNode = nil + } } if let (forwardInfoSize, forwardInfoApply) = forwardInfoSizeApply { @@ -869,8 +879,17 @@ class ChatMessageStickerItemNode: ChatMessageItemView { forwardBackgroundNode.update(size: forwardBackgroundNode.bounds.size, cornerRadius: 8.0, transition: .immediate) } } else if let forwardInfoNode = strongSelf.forwardInfoNode { - forwardInfoNode.removeFromSupernode() - strongSelf.forwardInfoNode = nil + if animation.isAnimated { + if let forwardInfoNode = strongSelf.forwardInfoNode { + strongSelf.forwardInfoNode = nil + forwardInfoNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak forwardInfoNode] _ in + forwardInfoNode?.removeFromSupernode() + }) + } + } else { + forwardInfoNode.removeFromSupernode() + strongSelf.forwardInfoNode = nil + } } if let actionButtonsSizeAndApply = actionButtonsSizeAndApply { diff --git a/submodules/TelegramUI/Sources/ForwardAccessoryPanelNode.swift b/submodules/TelegramUI/Sources/ForwardAccessoryPanelNode.swift index 9e1ed10de3..797829ace0 100644 --- a/submodules/TelegramUI/Sources/ForwardAccessoryPanelNode.swift +++ b/submodules/TelegramUI/Sources/ForwardAccessoryPanelNode.swift @@ -348,8 +348,14 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode { self.interfaceInteraction?.presentController(alertController, nil) } + private var previousTapTimestamp: Double? @objc func tapGesture(_ recognizer: UITapGestureRecognizer) { if case .ended = recognizer.state { + let timestamp = CFAbsoluteTimeGetCurrent() + if let previousTapTimestamp = self.previousTapTimestamp, previousTapTimestamp + 1.0 > timestamp { + return + } + self.previousTapTimestamp = CFAbsoluteTimeGetCurrent() self.interfaceInteraction?.presentForwardOptions(self) Queue.mainQueue().after(1.5) { self.updateThemeAndStrings(theme: self.theme, strings: self.strings, forwardOptionsState: self.forwardOptionsState, force: true) diff --git a/submodules/TelegramUI/Sources/MediaInputPaneTrendingItem.swift b/submodules/TelegramUI/Sources/MediaInputPaneTrendingItem.swift index 714d203d11..5867512049 100644 --- a/submodules/TelegramUI/Sources/MediaInputPaneTrendingItem.swift +++ b/submodules/TelegramUI/Sources/MediaInputPaneTrendingItem.swift @@ -92,21 +92,22 @@ final class TrendingTopItemNode: ASDisplayNode { self.theme = theme self.listAppearance = listAppearance - let backgroundColor: UIColor + let backgroundColor: UIColor? let foregroundColor: UIColor let shimmeringColor: UIColor if listAppearance { - backgroundColor = theme.list.plainBackgroundColor - foregroundColor = theme.list.itemPlainSeparatorColor.blitOver(backgroundColor, alpha: 0.3) + backgroundColor = nil + foregroundColor = theme.list.itemPlainSeparatorColor.blitOver(theme.list.plainBackgroundColor, alpha: 0.3) shimmeringColor = theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4) } else { - backgroundColor = theme.chat.inputMediaPanel.stickersBackgroundColor.withAlphaComponent(1.0) - foregroundColor = theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(backgroundColor, alpha: 0.15) + let color = theme.chat.inputMediaPanel.stickersBackgroundColor.withAlphaComponent(1.0) + backgroundColor = color + foregroundColor = theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(color, alpha: 0.15) shimmeringColor = theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3) } if let placeholderNode = self.placeholderNode, let file = self.file { - placeholderNode.update(backgroundColor: backgroundColor, foregroundColor: foregroundColor, shimmeringColor: shimmeringColor, data: file.immediateThumbnailData, size: placeholderNode.frame.size) + placeholderNode.update(backgroundColor: backgroundColor, foregroundColor: foregroundColor, shimmeringColor: shimmeringColor, data: file.immediateThumbnailData, size: self.itemSize ?? CGSize(width: 75.0, height: 75.0)) } }