From 5cead3ea989c4ae6affe4553e51dcb4c52055498 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 13 Jan 2023 22:42:05 +0400 Subject: [PATCH] Various improvements --- .../ChatMessageAttachedContentNode.swift | 41 ++++++++++++++++--- .../ChatMessageContactBubbleContentNode.swift | 2 +- .../ChatMessageTextBubbleContentNode.swift | 2 +- ...tMessageUnsupportedBubbleContentNode.swift | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift index 061db0c346..ac691471b3 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAttachedContentNode.swift @@ -19,6 +19,7 @@ import TextNodeWithEntities import AnimationCache import MultiAnimationRenderer import ChatControllerInteraction +import ShimmerEffect private let buttonFont = Font.semibold(13.0) @@ -47,6 +48,7 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { private let iconNode: ASImageNode private let highlightedTextNode: TextNode private let backgroundNode: ASImageNode + private let shimmerEffectNode: ShimmerEffectForegroundNode private var regularImage: UIImage? private var highlightedImage: UIImage? @@ -54,6 +56,8 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { private var highlightedIconImage: UIImage? var pressed: (() -> Void)? + + private var titleColor: UIColor? init() { self.textNode = TextNode() @@ -61,6 +65,9 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { self.highlightedTextNode = TextNode() self.highlightedTextNode.isUserInteractionEnabled = false + self.shimmerEffectNode = ShimmerEffectForegroundNode() + self.shimmerEffectNode.cornerRadius = 5.0 + self.backgroundNode = ASImageNode() self.backgroundNode.isLayerBacked = true self.backgroundNode.displayWithoutProcessing = true @@ -73,6 +80,7 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { super.init() + self.addSubnode(self.shimmerEffectNode) self.addSubnode(self.backgroundNode) self.addSubnode(self.textNode) self.addSubnode(self.highlightedTextNode) @@ -109,7 +117,26 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { self.pressed?() } - static func asyncLayout(_ current: ChatMessageAttachedContentButtonNode?) -> (_ width: CGFloat, _ regularImage: UIImage, _ highlightedImage: UIImage, _ iconImage: UIImage?, _ highlightedIconImage: UIImage?, _ title: String, _ titleColor: UIColor, _ highlightedTitleColor: UIColor) -> (CGFloat, (CGFloat) -> (CGSize, () -> ChatMessageAttachedContentButtonNode)) { + func startShimmering() { + guard let titleColor = self.titleColor else { + return + } + self.shimmerEffectNode.isHidden = false + self.shimmerEffectNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + + let backgroundFrame = self.backgroundNode.frame + self.shimmerEffectNode.frame = backgroundFrame + self.shimmerEffectNode.updateAbsoluteRect(CGRect(origin: .zero, size: backgroundFrame.size), within: backgroundFrame.size) + self.shimmerEffectNode.update(backgroundColor: .clear, foregroundColor: titleColor.withAlphaComponent(0.3), horizontal: true, effectSize: nil, globalTimeOffset: false, duration: nil) + } + + func stopShimmering() { + self.shimmerEffectNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak self] _ in + self?.shimmerEffectNode.isHidden = true + }) + } + + static func asyncLayout(_ current: ChatMessageAttachedContentButtonNode?) -> (_ width: CGFloat, _ regularImage: UIImage, _ highlightedImage: UIImage, _ iconImage: UIImage?, _ highlightedIconImage: UIImage?, _ title: String, _ titleColor: UIColor, _ highlightedTitleColor: UIColor, _ inProgress: Bool) -> (CGFloat, (CGFloat) -> (CGSize, () -> ChatMessageAttachedContentButtonNode)) { let previousRegularImage = current?.regularImage let previousHighlightedImage = current?.highlightedImage let previousRegularIconImage = current?.regularIconImage @@ -118,7 +145,7 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { let maybeMakeTextLayout = (current?.textNode).flatMap(TextNode.asyncLayout) let maybeMakeHighlightedTextLayout = (current?.highlightedTextNode).flatMap(TextNode.asyncLayout) - return { width, regularImage, highlightedImage, iconImage, highlightedIconImage, title, titleColor, highlightedTitleColor in + return { width, regularImage, highlightedImage, iconImage, highlightedIconImage, title, titleColor, highlightedTitleColor, inProgress in let targetNode: ChatMessageAttachedContentButtonNode if let current = current { targetNode = current @@ -175,6 +202,8 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { return (CGSize(width: refinedWidth, height: 33.0), { targetNode.accessibilityLabel = title + targetNode.titleColor = titleColor + if let updatedRegularImage = updatedRegularImage { targetNode.regularImage = updatedRegularImage if !targetNode.textNode.isHidden { @@ -203,8 +232,9 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode { let _ = textApply() let _ = highlightedTextApply() - targetNode.backgroundNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: refinedWidth, height: 33.0)) + let backgroundFrame = CGRect(origin: CGPoint(), size: CGSize(width: refinedWidth, height: 33.0)) var textFrame = CGRect(origin: CGPoint(x: floor((refinedWidth - textSize.size.width) / 2.0), y: floor((34.0 - textSize.size.height) / 2.0)), size: textSize.size) + targetNode.backgroundNode.frame = backgroundFrame if let image = targetNode.iconNode.image { textFrame.origin.x += floor(image.size.width / 2.0) targetNode.iconNode.frame = CGRect(origin: CGPoint(x: textFrame.minX - image.size.width - 5.0, y: textFrame.minY + 2.0), size: image.size) @@ -782,7 +812,7 @@ final class ChatMessageAttachedContentNode: ASDisplayNode { let bubbleColor = bubbleColorComponents(theme: presentationData.theme.theme, incoming: false, wallpaper: !presentationData.theme.wallpaper.isEmpty) titleHighlightedColor = bubbleColor.fill[0] } - let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, buttonIconImage, buttonHighlightedIconImage, actionTitle, titleColor, titleHighlightedColor) + let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, buttonIconImage, buttonHighlightedIconImage, actionTitle, titleColor, titleHighlightedColor, false) boundingSize.width = max(buttonWidth, boundingSize.width) continueActionButtonLayout = continueLayout } @@ -934,8 +964,7 @@ final class ChatMessageAttachedContentNode: ASDisplayNode { if let updateImageSignal = updateInlineImageSignal { strongSelf.inlineImageNode.setSignal(updateImageSignal) } - - strongSelf.inlineImageNode.frame = imageFrame + animation.animator.updateFrame(layer: strongSelf.inlineImageNode.layer, frame: imageFrame, completion: nil) if strongSelf.inlineImageNode.supernode == nil { strongSelf.addSubnode(strongSelf.inlineImageNode) } diff --git a/submodules/TelegramUI/Sources/ChatMessageContactBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageContactBubbleContentNode.swift index 746ce8efea..4e2679138f 100644 --- a/submodules/TelegramUI/Sources/ChatMessageContactBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageContactBubbleContentNode.swift @@ -260,7 +260,7 @@ class ChatMessageContactBubbleContentNode: ChatMessageBubbleContentNode { avatarPlaceholderColor = item.presentationData.theme.theme.chat.message.outgoing.mediaPlaceholderColor } - let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, nil, nil, item.presentationData.strings.Conversation_ViewContactDetails, titleColor, titleHighlightedColor) + let (buttonWidth, continueLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, nil, nil, item.presentationData.strings.Conversation_ViewContactDetails, titleColor, titleHighlightedColor, false) var maxContentWidth: CGFloat = avatarSize.width + 7.0 if let statusSuggestedWidthAndContinue = statusSuggestedWidthAndContinue { diff --git a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift index 159951cb98..00a2c7b10a 100644 --- a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift @@ -644,7 +644,7 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode { } } - if let spoilerRects = spoilerRects, !spoilerRects.isEmpty, !(self.dustNode?.isRevealed ?? true) { + if let spoilerRects = spoilerRects, !spoilerRects.isEmpty, let dustNode = self.dustNode, !dustNode.isRevealed { } else if let rects = rects { let linkHighlightingNode: LinkHighlightingNode diff --git a/submodules/TelegramUI/Sources/ChatMessageUnsupportedBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageUnsupportedBubbleContentNode.swift index a7e6bba0ad..dd9a2204b6 100644 --- a/submodules/TelegramUI/Sources/ChatMessageUnsupportedBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageUnsupportedBubbleContentNode.swift @@ -56,7 +56,7 @@ final class ChatMessageUnsupportedBubbleContentNode: ChatMessageBubbleContentNod let bubbleColor = bubbleColorComponents(theme: presentationData.theme.theme, incoming: false, wallpaper: !presentationData.theme.wallpaper.isEmpty) titleHighlightedColor = bubbleColor.fill[0] } - let (buttonWidth, continueActionButtonLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, nil, nil, presentationData.strings.Conversation_UpdateTelegram, titleColor, titleHighlightedColor) + let (buttonWidth, continueActionButtonLayout) = makeButtonLayout(constrainedSize.width, buttonImage, buttonHighlightedImage, nil, nil, presentationData.strings.Conversation_UpdateTelegram, titleColor, titleHighlightedColor, false) let initialWidth = buttonWidth + insets.left + insets.right