Various improvements

This commit is contained in:
Ilya Laktyushin
2023-01-13 22:42:05 +04:00
parent a37c84aa68
commit 5cead3ea98
4 changed files with 38 additions and 9 deletions

View File

@@ -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?
@@ -55,12 +57,17 @@ final class ChatMessageAttachedContentButtonNode: HighlightTrackingButtonNode {
var pressed: (() -> Void)?
private var titleColor: UIColor?
init() {
self.textNode = TextNode()
self.textNode.isUserInteractionEnabled = false
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)
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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