Fix trending video stickerpack thumbnail

This commit is contained in:
Ilya Laktyushin 2022-02-01 23:45:29 +03:00
parent 0624afd58b
commit 8bd663e908
2 changed files with 40 additions and 15 deletions

View File

@ -743,14 +743,18 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
transition.updateFrame(node: strongSelf.statusNode, frame: CGRect(origin: CGPoint(x: leftInset + revealOffset + editingOffset, y: strongSelf.titleNode.frame.maxY + titleSpacing), size: statusLayout.size))
let boundingSize = CGSize(width: 34.0, height: 34.0)
if let thumbnailItem = thumbnailItem, let imageSize = imageSize {
let imageFrame = CGRect(origin: CGPoint(x: params.leftInset + revealOffset + editingOffset + 15.0 + floor((boundingSize.width - imageSize.width) / 2.0), y: floor((layout.contentSize.height - imageSize.height) / 2.0)), size: imageSize)
let imageFrame: CGRect
if let imageSize = imageSize {
imageFrame = CGRect(origin: CGPoint(x: params.leftInset + revealOffset + editingOffset + 15.0 + floor((boundingSize.width - imageSize.width) / 2.0), y: floor((layout.contentSize.height - imageSize.height) / 2.0)), size: imageSize)
} else {
imageFrame = CGRect()
}
if let thumbnailItem = thumbnailItem {
transition.updateFrame(node: strongSelf.imageNode, frame: imageFrame)
var thumbnailDimensions = PixelDimensions(width: 512, height: 512)
switch thumbnailItem {
case let .still(representation):
thumbnailDimensions = representation.dimensions
case .still:
break
case let .animated(resource, _, isVideo):
let animationNode: AnimatedStickerNode
if let current = strongSelf.animationNode {
@ -769,12 +773,23 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode {
transition.updateFrame(node: animationNode, frame: imageFrame)
}
}
}
if let placeholderNode = strongSelf.placeholderNode {
var imageSize = PixelDimensions(width: 512, height: 512)
var immediateThumbnailData: Data?
if let data = item.packInfo.immediateThumbnailData {
if item.packInfo.flags.contains(.isVideo) {
imageSize = PixelDimensions(width: 100, height: 100)
}
immediateThumbnailData = data
} else if let data = item.topItem?.file.immediateThumbnailData {
immediateThumbnailData = data
}
placeholderNode.frame = imageFrame
placeholderNode.update(backgroundColor: nil, foregroundColor: item.presentationData.theme.list.disclosureArrowColor.blitOver(item.presentationData.theme.list.itemBlocksBackgroundColor, alpha: 0.55), shimmeringColor: item.presentationData.theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), data: item.packInfo.immediateThumbnailData, size: imageFrame.size, imageSize: thumbnailDimensions.cgSize)
}
placeholderNode.update(backgroundColor: nil, foregroundColor: item.presentationData.theme.list.disclosureArrowColor.blitOver(item.presentationData.theme.list.itemBlocksBackgroundColor, alpha: 0.55), shimmeringColor: item.presentationData.theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), data: immediateThumbnailData, size: imageFrame.size, imageSize: imageSize.cgSize)
}
if let updatedImageSignal = updatedImageSignal {

View File

@ -275,7 +275,6 @@ private final class FeaturedPackItemNode: ListViewItemNode {
if self.currentThumbnailItem != thumbnailItem {
self.currentThumbnailItem = thumbnailItem
let thumbnailDimensions = PixelDimensions(width: 512, height: 512)
if let thumbnailItem = thumbnailItem {
switch thumbnailItem {
case let .still(representation):
@ -298,6 +297,7 @@ private final class FeaturedPackItemNode: ListViewItemNode {
animatedStickerNode = AnimatedStickerNode()
animatedStickerNode.started = { [weak self] in
self?.imageNode.isHidden = true
self?.removePlaceholder(animated: false)
}
self.animatedStickerNode = animatedStickerNode
if let placeholderNode = self.placeholderNode {
@ -313,11 +313,21 @@ private final class FeaturedPackItemNode: ListViewItemNode {
self.stickerFetchedDisposable.set(fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: resourceReference).start())
}
}
}
if let placeholderNode = self.placeholderNode {
let imageSize = boundingImageSize
placeholderNode.update(backgroundColor: theme.chat.inputMediaPanel.stickersBackgroundColor.withAlphaComponent(1.0), foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(theme.chat.inputMediaPanel.stickersBackgroundColor, alpha: 0.15), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), data: info.immediateThumbnailData, size: imageSize, imageSize: thumbnailDimensions.cgSize)
var imageSize = PixelDimensions(width: 512, height: 512)
var immediateThumbnailData: Data?
if let data = info.immediateThumbnailData {
if info.flags.contains(.isVideo) {
imageSize = PixelDimensions(width: 100, height: 100)
}
immediateThumbnailData = data
} else if let data = item?.file.immediateThumbnailData {
immediateThumbnailData = data
}
placeholderNode.update(backgroundColor: theme.chat.inputMediaPanel.stickersBackgroundColor.withAlphaComponent(1.0), foregroundColor: theme.chat.inputMediaPanel.stickersSectionTextColor.blitOver(theme.chat.inputMediaPanel.stickersBackgroundColor, alpha: 0.15), shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.3), data: immediateThumbnailData, size: boundingImageSize, imageSize: imageSize.cgSize)
}
self.containerNode.frame = CGRect(origin: CGPoint(), size: boundingSize)