Various improvements

This commit is contained in:
Ilya Laktyushin 2023-12-17 22:45:25 +04:00
parent 461c780517
commit 1fa4bd2267
6 changed files with 64 additions and 47 deletions

View File

@ -243,18 +243,21 @@ public final class RadialStatusNode: ASControlNode {
}
private let enableBlur: Bool
private let isPreview: Bool
public private(set) var state: RadialStatusNodeState = .none
private var staticBackgroundNode: ASImageNode?
private var backgroundNode: NavigationBackgroundNode?
private var currentBackgroundNodeColor: UIColor?
private var contentNode: RadialStatusContentNode?
private var nextContentNode: RadialStatusContentNode?
public init(backgroundNodeColor: UIColor, enableBlur: Bool = false) {
self.enableBlur = enableBlur
public init(backgroundNodeColor: UIColor, enableBlur: Bool = false, isPreview: Bool = false) {
self.backgroundNodeColor = backgroundNodeColor
self.enableBlur = enableBlur
self.isPreview = isPreview
super.init()
}
@ -325,6 +328,7 @@ public final class RadialStatusNode: ASControlNode {
} else {
self.contentNode = node
if let contentNode = self.contentNode {
contentNode.displaysAsynchronously = self.displaysAsynchronously
contentNode.frame = self.bounds
contentNode.prepareAnimateIn(from: nil)
self.addSubnode(contentNode)
@ -354,27 +358,40 @@ public final class RadialStatusNode: ASControlNode {
if updated {
if let color = color {
if let backgroundNode = self.backgroundNode {
backgroundNode.updateColor(color: color, transition: .immediate)
self.currentBackgroundNodeColor = color
completion()
} else {
let backgroundNode = NavigationBackgroundNode(color: color, enableBlur: self.enableBlur)
self.currentBackgroundNodeColor = color
backgroundNode.frame = self.bounds
backgroundNode.update(size: backgroundNode.bounds.size, cornerRadius: backgroundNode.bounds.size.height / 2.0, transition: .immediate)
self.backgroundNode = backgroundNode
self.insertSubnode(backgroundNode, at: 0)
if animated {
backgroundNode.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2, removeOnCompletion: false)
backgroundNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
completion()
})
if self.isPreview {
let backgroundNode: ASImageNode
if let current = self.staticBackgroundNode {
backgroundNode = current
} else {
backgroundNode = ASImageNode()
backgroundNode.image = generateFilledCircleImage(diameter: 50.0, color: self.backgroundNodeColor)
self.insertSubnode(backgroundNode, at: 0)
self.staticBackgroundNode = backgroundNode
}
backgroundNode.frame = self.bounds
} else {
if let backgroundNode = self.backgroundNode {
backgroundNode.updateColor(color: color, transition: .immediate)
self.currentBackgroundNodeColor = color
completion()
} else {
let backgroundNode = NavigationBackgroundNode(color: color, enableBlur: self.enableBlur)
self.currentBackgroundNodeColor = color
backgroundNode.frame = self.bounds
backgroundNode.update(size: backgroundNode.bounds.size, cornerRadius: backgroundNode.bounds.size.height / 2.0, transition: .immediate)
self.backgroundNode = backgroundNode
self.insertSubnode(backgroundNode, at: 0)
if animated {
backgroundNode.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2, removeOnCompletion: false)
backgroundNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
completion()
})
} else {
completion()
}
}
}
} else if let backgroundNode = self.backgroundNode {

View File

@ -341,8 +341,8 @@ public final class PrincipalThemeEssentialGraphics {
self.clockMediaMinImage = emptyImage
self.clockFreeFrameImage = emptyImage
self.clockFreeMinImage = emptyImage
self.dateAndStatusMediaBackground = emptyImage
self.dateAndStatusFreeBackground = emptyImage
self.dateAndStatusMediaBackground = generateStretchableFilledCircleImage(diameter: 18.0, color: theme.message.mediaDateAndStatusFillColor)!
self.dateAndStatusFreeBackground = generateStretchableFilledCircleImage(diameter: 18.0, color: serviceColor.dateFillStatic)!
let impressionCountImage = UIImage(bundleImageName: "Chat/Message/ImpressionCount")!
self.incomingDateAndStatusImpressionIcon = generateTintedImage(image: impressionCountImage, color: theme.message.incoming.secondaryTextColor)!

View File

@ -2092,7 +2092,7 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
let statusSuggestedWidthAndContinue = mosaicStatusLayout(ChatMessageDateAndStatusNode.Arguments(
context: item.context,
presentationData: item.presentationData,
edited: edited,
edited: edited && !item.presentationData.isPreview,
impressionCount: viewCount,
dateText: dateText,
type: statusType,

View File

@ -1225,7 +1225,7 @@ public class ChatMessageInteractiveInstantVideoNode: ASDisplayNode {
if progressRequired {
if self.statusNode == nil {
let statusNode = RadialStatusNode(backgroundNodeColor: item.presentationData.theme.theme.chat.message.mediaOverlayControlColors.fillColor)
let statusNode = RadialStatusNode(backgroundNodeColor: item.presentationData.theme.theme.chat.message.mediaOverlayControlColors.fillColor, isPreview: item.presentationData.isPreview)
statusNode.displaysAsynchronously = !item.presentationData.isPreview
self.isUserInteractionEnabled = false
self.statusNode = statusNode

View File

@ -1254,7 +1254,7 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
uploading = true
}
if file.isVideo && !file.isVideoSticker && !isSecretMedia && automaticPlayback && !isStory && !uploading {
if file.isVideo && !file.isVideoSticker && !isSecretMedia && automaticPlayback && !isStory && !uploading && !presentationData.isPreview {
updateVideoFile = file
if hasCurrentVideoNode {
if let currentFile = currentMedia as? TelegramMediaFile {
@ -1796,6 +1796,9 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
}
}
}
if isPreview {
progressRequired = true
}
var radialStatusSize: CGFloat
if isSecretMedia {
@ -1805,7 +1808,8 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
}
if progressRequired {
if self.statusNode == nil {
let statusNode = RadialStatusNode(backgroundNodeColor: theme.chat.message.mediaOverlayControlColors.fillColor)
let statusNode = RadialStatusNode(backgroundNodeColor: theme.chat.message.mediaOverlayControlColors.fillColor, isPreview: isPreview)
statusNode.displaysAsynchronously = !isPreview
let imageSize = self.imageNode.bounds.size
statusNode.frame = CGRect(origin: CGPoint(x: floor(imageSize.width / 2.0 - radialStatusSize / 2.0), y: floor(imageSize.height / 2.0 - radialStatusSize / 2.0)), size: CGSize(width: radialStatusSize, height: radialStatusSize))
self.statusNode = statusNode
@ -1893,6 +1897,10 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
automaticPlayback = false
}
if isPreview {
muted = false
}
if let actualFetchStatus = self.actualFetchStatus {
if automaticPlayback || message.forwardInfo != nil {
fetchStatus = actualFetchStatus
@ -2069,6 +2077,9 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
}
}
}
if isPreview {
state = .play(messageTheme.mediaOverlayControlColors.foregroundColor)
}
if isSecretMedia {
let remainingTime: Int32?
@ -2119,12 +2130,11 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
})
statusNode.backgroundNodeColor = backgroundColor
}
if let badgeContent = badgeContent {
if var badgeContent = badgeContent {
if self.badgeNode == nil {
let badgeNode = ChatMessageInteractiveMediaBadge()
if isPreview {
badgeNode.durationNode.displaysAsynchronously = false
badgeNode.sizeNode?.displaysAsynchronously = false
}
var inset: CGFloat = 6.0
@ -2149,6 +2159,12 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
animated = false
}
if isPreview {
mediaDownloadState = nil
if case let .mediaDownload(backgroundColor, foregroundColor, duration, _ ,_ , _) = badgeContent {
badgeContent = .text(inset: 0.0, backgroundColor: backgroundColor, foregroundColor: foregroundColor, text: NSAttributedString(string: duration), iconName: nil)
}
}
self.badgeNode?.update(theme: theme, content: badgeContent, mediaDownloadState: mediaDownloadState, animated: animated)
} else if let badgeNode = self.badgeNode {
self.badgeNode = nil

View File

@ -83,7 +83,6 @@ public final class DrawingMessageRenderer {
private let containerNode: ASDisplayNode
private let messagesContainerNode: ASDisplayNode
private var dateHeaderNode: ListViewItemHeaderNode?
private var avatarHeaderNode: ListViewItemHeaderNode?
private var messageNodes: [ListViewItemNode]?
@ -156,7 +155,6 @@ public final class DrawingMessageRenderer {
let size = layout.size
let theme = presentationData.theme.withUpdated(preview: true)
let dateHeaderItem = self.context.sharedContext.makeChatMessageDateHeaderItem(context: self.context, timestamp: self.messages.first?.timestamp ?? 0, theme: theme, strings: presentationData.strings, wallpaper: presentationData.chatWallpaper, fontSize: presentationData.chatFontSize, chatBubbleCorners: presentationData.chatBubbleCorners, dateTimeFormat: presentationData.dateTimeFormat, nameOrder: presentationData.nameDisplayOrder)
let avatarHeaderItem = self.context.sharedContext.makeChatMessageAvatarHeaderItem(context: self.context, timestamp: self.messages.first?.timestamp ?? 0, peer: self.messages.first!.peers[self.messages.first!.author!.id]!, message: self.messages.first!, theme: theme, strings: presentationData.strings, wallpaper: presentationData.chatWallpaper, fontSize: presentationData.chatFontSize, chatBubbleCorners: presentationData.chatBubbleCorners, dateTimeFormat: presentationData.dateTimeFormat, nameOrder: presentationData.nameDisplayOrder)
@ -235,17 +233,6 @@ public final class DrawingMessageRenderer {
}
}
let dateHeaderNode: ListViewItemHeaderNode
if let currentDateHeaderNode = self.dateHeaderNode {
dateHeaderNode = currentDateHeaderNode
dateHeaderItem.updateNode(dateHeaderNode, previous: nil, next: dateHeaderItem)
} else {
dateHeaderNode = dateHeaderItem.node(synchronousLoad: true)
dateHeaderNode.subnodeTransform = CATransform3DMakeScale(-1.0, 1.0, 1.0)
// self.messagesContainerNode.addSubnode(dateHeaderNode)
self.dateHeaderNode = dateHeaderNode
}
let avatarHeaderNode: ListViewItemHeaderNode
if let currentAvatarHeaderNode = self.avatarHeaderNode {
avatarHeaderNode = currentAvatarHeaderNode
@ -257,9 +244,6 @@ public final class DrawingMessageRenderer {
self.avatarHeaderNode = avatarHeaderNode
}
dateHeaderNode.frame = CGRect(origin: CGPoint(x: 0.0, y: bottomOffset), size: CGSize(width: layout.size.width, height: dateHeaderItem.height))
dateHeaderNode.updateLayout(size: size, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right)
avatarHeaderNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 3.0), size: CGSize(width: layout.size.width, height: avatarHeaderItem.height))
avatarHeaderNode.updateLayout(size: size, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right)