Update sticker shimmer effects

This commit is contained in:
Ilya Laktyushin 2020-12-10 19:16:02 +04:00
parent bc2fcb8953
commit 2ac3467f00
7 changed files with 121 additions and 349 deletions

View File

@ -565,10 +565,12 @@ class TabBarNode: ASDisplayNode {
if let callsTabBarNodeContainer = callsTabBarNodeContainer { if let callsTabBarNodeContainer = callsTabBarNodeContainer {
tabBarNodeContainers.remove(at: 1) tabBarNodeContainers.remove(at: 1)
transition.updateAlpha(node: callsTabBarNodeContainer.imageNode, alpha: 0.0) transition.updateAlpha(node: callsTabBarNodeContainer.imageNode, alpha: 0.0)
callsTabBarNodeContainer.imageNode.isUserInteractionEnabled = false
} }
} else { } else {
if let callsTabBarNodeContainer = callsTabBarNodeContainer { if let callsTabBarNodeContainer = callsTabBarNodeContainer {
transition.updateAlpha(node: callsTabBarNodeContainer.imageNode, alpha: 1.0) transition.updateAlpha(node: callsTabBarNodeContainer.imageNode, alpha: 1.0)
callsTabBarNodeContainer.imageNode.isUserInteractionEnabled = true
} }
} }
@ -641,6 +643,9 @@ class TabBarNode: ASDisplayNode {
for i in 0 ..< self.tabBarNodeContainers.count { for i in 0 ..< self.tabBarNodeContainers.count {
let node = self.tabBarNodeContainers[i].imageNode let node = self.tabBarNodeContainers[i].imageNode
if !node.isUserInteractionEnabled {
continue
}
let distance = abs(location.x - node.position.x) let distance = abs(location.x - node.position.x)
if let previousClosestNode = closestNode { if let previousClosestNode = closestNode {
if previousClosestNode.1 > distance { if previousClosestNode.1 > distance {

View File

@ -1,9 +1,6 @@
import Foundation import Foundation
import AsyncDisplayKit import AsyncDisplayKit
import Display import Display
import Postbox
import TelegramPresentationData
import GZip
private final class ShimmerEffectForegroundNode: ASDisplayNode { private final class ShimmerEffectForegroundNode: ASDisplayNode {
private var currentBackgroundColor: UIColor? private var currentBackgroundColor: UIColor?
@ -142,7 +139,7 @@ private func decodeStickerThumbnailData(_ data: Data) -> String {
return string return string
} }
class StickerShimmerEffectNode: ASDisplayNode { public class StickerShimmerEffectNode: ASDisplayNode {
private let backgroundNode: ASDisplayNode private let backgroundNode: ASDisplayNode
private let effectNode: ShimmerEffectForegroundNode private let effectNode: ShimmerEffectForegroundNode
private let foregroundNode: ASImageNode private let foregroundNode: ASImageNode
@ -155,7 +152,7 @@ class StickerShimmerEffectNode: ASDisplayNode {
private var currentShimmeringColor: UIColor? private var currentShimmeringColor: UIColor?
private var currentSize = CGSize() private var currentSize = CGSize()
override init() { public override init() {
self.backgroundNode = ASDisplayNode() self.backgroundNode = ASDisplayNode()
self.effectNode = ShimmerEffectForegroundNode() self.effectNode = ShimmerEffectForegroundNode()
self.foregroundNode = ASImageNode() self.foregroundNode = ASImageNode()
@ -172,6 +169,9 @@ class StickerShimmerEffectNode: ASDisplayNode {
} }
public func update(backgroundColor: UIColor?, foregroundColor: UIColor, shimmeringColor: UIColor, data: Data?, size: CGSize) { public func update(backgroundColor: UIColor?, foregroundColor: UIColor, shimmeringColor: UIColor, data: Data?, size: CGSize) {
if data == nil {
return
}
if self.currentData == data, let currentBackgroundColor = self.currentBackgroundColor, currentBackgroundColor.isEqual(backgroundColor), let currentForegroundColor = self.currentForegroundColor, currentForegroundColor.isEqual(foregroundColor), let currentShimmeringColor = self.currentShimmeringColor, currentShimmeringColor.isEqual(shimmeringColor), self.currentSize == size { if self.currentData == data, let currentBackgroundColor = self.currentBackgroundColor, currentBackgroundColor.isEqual(backgroundColor), let currentForegroundColor = self.currentForegroundColor, currentForegroundColor.isEqual(foregroundColor), let currentShimmeringColor = self.currentShimmeringColor, currentShimmeringColor.isEqual(shimmeringColor), self.currentSize == size {
return return
} }

View File

@ -61,7 +61,7 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
private var isEmpty: Bool? private var isEmpty: Bool?
private let imageNode: TransformImageNode private let imageNode: TransformImageNode
private var animationNode: AnimatedStickerNode? private var animationNode: AnimatedStickerNode?
private var placeholderNode: ShimmerEffectNode? private var placeholderNode: StickerShimmerEffectNode?
private var theme: PresentationTheme? private var theme: PresentationTheme?
@ -86,7 +86,8 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
override init() { override init() {
self.imageNode = TransformImageNode() self.imageNode = TransformImageNode()
self.imageNode.isLayerBacked = !smartInvertColorsEnabled() self.imageNode.isLayerBacked = !smartInvertColorsEnabled()
self.placeholderNode = ShimmerEffectNode() self.placeholderNode = StickerShimmerEffectNode()
self.placeholderNode?.isUserInteractionEnabled = false
super.init() super.init()
@ -117,9 +118,11 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
if !animated { if !animated {
placeholderNode.removeFromSupernode() placeholderNode.removeFromSupernode()
} else { } else {
placeholderNode.allowsGroupOpacity = true
placeholderNode.alpha = 0.0 placeholderNode.alpha = 0.0
placeholderNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak placeholderNode] _ in placeholderNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak placeholderNode] _ in
placeholderNode?.removeFromSupernode() placeholderNode?.removeFromSupernode()
placeholderNode?.allowsGroupOpacity = false
}) })
} }
} }
@ -181,9 +184,6 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
self.setNeedsLayout() self.setNeedsLayout()
} }
self.isEmpty = isEmpty self.isEmpty = isEmpty
//self.updateSelectionState(animated: false)
//self.updateHiddenMedia()
} }
override func layout() { override func layout() {
@ -197,8 +197,8 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
let placeholderFrame = CGRect(origin: CGPoint(x: floor((bounds.width - boundingSize.width) / 2.0), y: floor((bounds.height - boundingSize.height) / 2.0)), size: boundingSize) let placeholderFrame = CGRect(origin: CGPoint(x: floor((bounds.width - boundingSize.width) / 2.0), y: floor((bounds.height - boundingSize.height) / 2.0)), size: boundingSize)
placeholderNode.frame = bounds placeholderNode.frame = bounds
if let theme = self.theme { if let theme = self.theme, let (_, stickerItem) = self.currentState, let item = stickerItem {
placeholderNode.update(backgroundColor: theme.list.itemBlocksBackgroundColor, foregroundColor: theme.list.mediaPlaceholderColor, shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 10.0)], size: bounds.size) placeholderNode.update(backgroundColor: theme.list.itemBlocksBackgroundColor, foregroundColor: theme.list.mediaPlaceholderColor, shimmeringColor: theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), data: item.file.immediateThumbnailData, size: placeholderFrame.size)
} }
} }

View File

@ -21,6 +21,7 @@ import Markdown
import ManagedAnimationNode import ManagedAnimationNode
import SlotMachineAnimationNode import SlotMachineAnimationNode
import UniversalMediaPlayer import UniversalMediaPlayer
import ShimmerEffect
private let nameFont = Font.medium(14.0) private let nameFont = Font.medium(14.0)
private let inlineBotPrefixFont = Font.regular(14.0) private let inlineBotPrefixFont = Font.regular(14.0)

View File

@ -51,7 +51,7 @@ final class HorizontalStickerGridItemNode: GridItemNode {
private var currentState: (Account, HorizontalStickerGridItem, CGSize)? private var currentState: (Account, HorizontalStickerGridItem, CGSize)?
private let imageNode: TransformImageNode private let imageNode: TransformImageNode
private var animationNode: AnimatedStickerNode? private var animationNode: AnimatedStickerNode?
private var placeholderNode: ShimmerEffectNode? private var placeholderNode: StickerShimmerEffectNode?
private let stickerFetchedDisposable = MetaDisposable() private let stickerFetchedDisposable = MetaDisposable()
@ -81,7 +81,7 @@ final class HorizontalStickerGridItemNode: GridItemNode {
override init() { override init() {
self.imageNode = TransformImageNode() self.imageNode = TransformImageNode()
self.placeholderNode = ShimmerEffectNode() self.placeholderNode = StickerShimmerEffectNode()
super.init() super.init()
@ -114,9 +114,11 @@ final class HorizontalStickerGridItemNode: GridItemNode {
if !animated { if !animated {
placeholderNode.removeFromSupernode() placeholderNode.removeFromSupernode()
} else { } else {
placeholderNode.allowsGroupOpacity = true
placeholderNode.alpha = 0.0 placeholderNode.alpha = 0.0
placeholderNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak placeholderNode] _ in placeholderNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak placeholderNode] _ in
placeholderNode?.removeFromSupernode() placeholderNode?.removeFromSupernode()
placeholderNode?.allowsGroupOpacity = false
}) })
} }
} }
@ -188,8 +190,8 @@ final class HorizontalStickerGridItemNode: GridItemNode {
let placeholderFrame = CGRect(origin: CGPoint(x: floor((bounds.width - boundingSize.width) / 2.0), y: floor((bounds.height - boundingSize.height) / 2.0)), size: boundingSize) let placeholderFrame = CGRect(origin: CGPoint(x: floor((bounds.width - boundingSize.width) / 2.0), y: floor((bounds.height - boundingSize.height) / 2.0)), size: boundingSize)
placeholderNode.frame = bounds placeholderNode.frame = bounds
if let theme = self.currentState?.1.theme { if let theme = self.currentState?.1.theme, let file = self.currentState?.1.file {
placeholderNode.update(backgroundColor: theme.list.plainBackgroundColor, foregroundColor: theme.list.mediaPlaceholderColor.mixedWith(theme.list.plainBackgroundColor, alpha: 0.4), shimmeringColor: theme.list.mediaPlaceholderColor.withAlphaComponent(0.3), shapes: [.roundedRect(rect: placeholderFrame, cornerRadius: 10.0)], size: bounds.size) placeholderNode.update(backgroundColor: theme.list.plainBackgroundColor, foregroundColor: theme.list.mediaPlaceholderColor.mixedWith(theme.list.plainBackgroundColor, alpha: 0.4), shimmeringColor: theme.list.mediaPlaceholderColor.withAlphaComponent(0.3), data: file.immediateThumbnailData, size: bounds.size)
} }
} }

View File

@ -11,61 +11,7 @@ import StickerResources
import AccountContext import AccountContext
import AnimatedStickerNode import AnimatedStickerNode
import TelegramAnimatedStickerNode import TelegramAnimatedStickerNode
import ShimmerEffect
class MediaInputPaneTrendingItem: ListViewItem {
let account: Account
let theme: PresentationTheme
let strings: PresentationStrings
let interaction: TrendingPaneInteraction
let info: StickerPackCollectionInfo
let topItems: [StickerPackItem]
let installed: Bool
let unread: Bool
init(account: Account, theme: PresentationTheme, strings: PresentationStrings, interaction: TrendingPaneInteraction, info: StickerPackCollectionInfo, topItems: [StickerPackItem], installed: Bool, unread: Bool) {
self.account = account
self.theme = theme
self.strings = strings
self.interaction = interaction
self.info = info
self.topItems = topItems
self.installed = installed
self.unread = unread
}
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
async {
let node = MediaInputPaneTrendingItemNode()
let (layout, apply) = node.asyncLayout()(self, params)
node.contentSize = layout.contentSize
node.insets = layout.insets
Queue.mainQueue().async {
completion(node, {
return (nil, { info in apply(synchronousLoads && info.isOnScreen) })
})
}
}
}
func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: @escaping () -> ListViewItemNode, params: ListViewItemLayoutParams, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping (ListViewItemApply) -> Void) -> Void) {
Queue.mainQueue().async {
if let nodeValue = node() as? MediaInputPaneTrendingItemNode {
let makeLayout = nodeValue.asyncLayout()
async {
let (layout, apply) = makeLayout(self, params)
Queue.mainQueue().async {
completion(layout, { _ in
apply(false)
})
}
}
}
}
}
}
private let titleFont = Font.bold(16.0) private let titleFont = Font.bold(16.0)
private let statusFont = Font.regular(15.0) private let statusFont = Font.regular(15.0)
@ -74,7 +20,10 @@ private let buttonFont = Font.medium(13.0)
final class TrendingTopItemNode: ASDisplayNode { final class TrendingTopItemNode: ASDisplayNode {
private let imageNode: TransformImageNode private let imageNode: TransformImageNode
private var animationNode: AnimatedStickerNode? private var animationNode: AnimatedStickerNode?
private var placeholderNode: StickerShimmerEffectNode?
public private(set) var file: TelegramMediaFile? = nil public private(set) var file: TelegramMediaFile? = nil
public private(set) var theme: PresentationTheme?
private var listAppearance = false
private var itemSize: CGSize? private var itemSize: CGSize?
private let loadDisposable = MetaDisposable() private let loadDisposable = MetaDisposable()
@ -91,15 +40,77 @@ final class TrendingTopItemNode: ASDisplayNode {
override init() { override init() {
self.imageNode = TransformImageNode() self.imageNode = TransformImageNode()
self.imageNode.contentAnimations = [.subsequentUpdates] self.imageNode.contentAnimations = [.subsequentUpdates]
self.placeholderNode = StickerShimmerEffectNode()
self.placeholderNode?.isUserInteractionEnabled = false
super.init() super.init()
self.addSubnode(self.imageNode) self.addSubnode(self.imageNode)
if let placeholderNode = self.placeholderNode {
self.addSubnode(placeholderNode)
}
var firstTime = true
self.imageNode.imageUpdated = { [weak self] image in
guard let strongSelf = self else {
return
}
if image != nil {
strongSelf.removePlaceholder(animated: !firstTime)
}
firstTime = false
}
} }
deinit { deinit {
self.loadDisposable.dispose() self.loadDisposable.dispose()
} }
private func removePlaceholder(animated: Bool) {
if let placeholderNode = self.placeholderNode {
self.placeholderNode = nil
if !animated {
placeholderNode.removeFromSupernode()
} else {
placeholderNode.allowsGroupOpacity = true
placeholderNode.alpha = 0.0
placeholderNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, completion: { [weak placeholderNode] _ in
placeholderNode?.removeFromSupernode()
placeholderNode?.allowsGroupOpacity = false
})
}
}
}
private var absoluteLocation: (CGRect, CGSize)?
func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
self.absoluteLocation = (rect, containerSize)
if let placeholderNode = placeholderNode {
placeholderNode.updateAbsoluteRect(rect, within: containerSize)
}
}
func update(theme: PresentationTheme, listAppearance: Bool) {
self.theme = theme
self.listAppearance = listAppearance
let backgroundColor: UIColor
let foregroundColor: UIColor
let shimmeringColor: UIColor
if listAppearance {
backgroundColor = theme.list.plainBackgroundColor
foregroundColor = theme.list.itemPlainSeparatorColor.blitOver(backgroundColor, 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)
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)
}
}
func setup(account: Account, item: StickerPackItem, itemSize: CGSize, synchronousLoads: Bool) { func setup(account: Account, item: StickerPackItem, itemSize: CGSize, synchronousLoads: Bool) {
self.file = item.file self.file = item.file
self.itemSize = itemSize self.itemSize = itemSize
@ -112,8 +123,13 @@ final class TrendingTopItemNode: ASDisplayNode {
animationNode = AnimatedStickerNode() animationNode = AnimatedStickerNode()
animationNode.transform = self.imageNode.transform animationNode.transform = self.imageNode.transform
animationNode.visibility = self.visibility animationNode.visibility = self.visibility
self.addSubnode(animationNode)
self.animationNode = animationNode self.animationNode = animationNode
if let placeholderNode = self.placeholderNode {
self.insertSubnode(animationNode, belowSubnode: placeholderNode)
} else {
self.addSubnode(animationNode)
}
} }
let dimensions = item.file.dimensions ?? PixelDimensions(width: 512, height: 512) let dimensions = item.file.dimensions ?? PixelDimensions(width: 512, height: 512)
let fittedDimensions = dimensions.cgSize.aspectFitted(CGSize(width: 160.0, height: 160.0)) let fittedDimensions = dimensions.cgSize.aspectFitted(CGSize(width: 160.0, height: 160.0))
@ -161,285 +177,17 @@ final class TrendingTopItemNode: ASDisplayNode {
self.imageNode.frame = self.bounds self.imageNode.frame = self.bounds
self.animationNode?.updateLayout(size: self.bounds.size) self.animationNode?.updateLayout(size: self.bounds.size)
}
} let size = self.bounds.size
let boundingSize = size
class MediaInputPaneTrendingItemNode: ListViewItemNode {
private let titleNode: TextNode if let placeholderNode = self.placeholderNode {
private let descriptionNode: TextNode let placeholderFrame = CGRect(origin: CGPoint(x: floor((size.width - boundingSize.width) / 2.0), y: floor((size.height - boundingSize.height) / 2.0)), size: boundingSize)
private let unreadNode: ASImageNode placeholderNode.frame = placeholderFrame
private let installTextNode: TextNode
private let installBackgroundNode: ASImageNode
private let installButtonNode: HighlightTrackingButtonNode
private var itemNodes: [TrendingTopItemNode]
private var item: MediaInputPaneTrendingItem?
private let preloadDisposable = MetaDisposable()
private let readDisposable = MetaDisposable()
override var visibility: ListViewItemNodeVisibility {
didSet {
let wasVisible = oldValue != .none
let isVisible = self.visibility != .none
if isVisible != wasVisible { if let theme = self.theme {
for node in self.itemNodes { self.update(theme: theme, listAppearance: self.listAppearance)
node.visibility = isVisible
}
if isVisible {
if let item = self.item, item.unread {
self.readDisposable.set((
markFeaturedStickerPacksAsSeenInteractively(postbox: item.account.postbox, ids: [item.info.id])
|> delay(1.0, queue: .mainQueue())
).start())
}
} else {
self.readDisposable.set(nil)
}
} }
} }
} }
init() {
self.titleNode = TextNode()
self.titleNode.isUserInteractionEnabled = false
self.titleNode.contentMode = .left
self.titleNode.contentsScale = UIScreen.main.scale
self.descriptionNode = TextNode()
self.descriptionNode.isUserInteractionEnabled = false
self.descriptionNode.contentMode = .left
self.descriptionNode.contentsScale = UIScreen.main.scale
self.unreadNode = ASImageNode()
self.unreadNode.isLayerBacked = true
self.unreadNode.displayWithoutProcessing = true
self.unreadNode.displaysAsynchronously = false
self.installTextNode = TextNode()
self.installTextNode.isUserInteractionEnabled = false
self.installTextNode.contentMode = .left
self.installTextNode.contentsScale = UIScreen.main.scale
self.installBackgroundNode = ASImageNode()
self.installBackgroundNode.isLayerBacked = true
self.installBackgroundNode.displayWithoutProcessing = true
self.installBackgroundNode.displaysAsynchronously = false
self.installButtonNode = HighlightTrackingButtonNode()
self.itemNodes = []
super.init(layerBacked: false, dynamicBounce: false)
self.addSubnode(self.titleNode)
self.addSubnode(self.descriptionNode)
self.addSubnode(self.unreadNode)
self.addSubnode(self.installBackgroundNode)
self.addSubnode(self.installTextNode)
self.addSubnode(self.installButtonNode)
self.installButtonNode.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self {
if highlighted {
strongSelf.installBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.installBackgroundNode.alpha = 0.4
strongSelf.installTextNode.layer.removeAnimation(forKey: "opacity")
strongSelf.installTextNode.alpha = 0.4
} else {
strongSelf.installBackgroundNode.alpha = 1.0
strongSelf.installBackgroundNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
strongSelf.installTextNode.alpha = 1.0
strongSelf.installTextNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
}
}
}
self.installButtonNode.addTarget(self, action: #selector(self.installPressed), forControlEvents: .touchUpInside)
}
deinit {
self.preloadDisposable.dispose()
self.readDisposable.dispose()
}
override func didLoad() {
super.didLoad()
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
}
func asyncLayout() -> (_ item: MediaInputPaneTrendingItem, _ params: ListViewItemLayoutParams) -> (ListViewItemNodeLayout, (Bool) -> Void) {
let makeInstallLayout = TextNode.asyncLayout(self.installTextNode)
let makeTitleLayout = TextNode.asyncLayout(self.titleNode)
let makeDescriptionLayout = TextNode.asyncLayout(self.descriptionNode)
let currentItem = self.item
return { item, params in
var updateButtonBackgroundImage: UIImage?
if currentItem?.theme !== item.theme {
updateButtonBackgroundImage = PresentationResourcesChat.chatInputMediaPanelAddPackButtonImage(item.theme)
}
let unreadImage = PresentationResourcesItemList.stickerUnreadDotImage(item.theme)
let leftInset: CGFloat = 14.0
let rightInset: CGFloat = 16.0
let (installLayout, installApply) = makeInstallLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.strings.Stickers_Install, font: buttonFont, textColor: item.theme.list.itemAccentColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - params.leftInset - params.rightInset - leftInset - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.info.title, font: titleFont, textColor: item.theme.list.itemPrimaryTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - params.leftInset - params.rightInset - leftInset - rightInset - 20.0 - installLayout.size.width, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let (descriptionLayout, descriptionApply) = makeDescriptionLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.strings.StickerPack_StickerCount(item.info.count), font: statusFont, textColor: item.theme.chat.inputMediaPanel.stickersSectionTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - params.leftInset - params.rightInset - leftInset - rightInset - 20.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
let contentSize: CGSize = CGSize(width: params.width, height: 120.0)
let insets: UIEdgeInsets = UIEdgeInsets(top: 8.0, left: 0.0, bottom: 0.0, right: 0.0)
let layout = ListViewItemNodeLayout(contentSize: contentSize, insets: insets)
var topItems = item.topItems
if topItems.count > 5 {
topItems.removeSubrange(5 ..< topItems.count)
}
return (layout, { [weak self] synchronousLoads in
if let strongSelf = self {
if (item.topItems.count < Int(item.info.count) || item.topItems.count < 5) && strongSelf.item?.info.id != item.info.id {
strongSelf.preloadDisposable.set(preloadedFeaturedStickerSet(network: item.account.network, postbox: item.account.postbox, id: item.info.id).start())
}
strongSelf.item = item
let _ = installApply()
let _ = titleApply()
let _ = descriptionApply()
if let updateButtonBackgroundImage = updateButtonBackgroundImage {
strongSelf.installBackgroundNode.image = updateButtonBackgroundImage
}
let installWidth: CGFloat = installLayout.size.width + 20.0
let buttonFrame = CGRect(origin: CGPoint(x: params.width - params.rightInset - rightInset - installWidth, y: 4.0), size: CGSize(width: installWidth, height: 26.0))
strongSelf.installBackgroundNode.frame = buttonFrame
strongSelf.installTextNode.frame = CGRect(origin: CGPoint(x: buttonFrame.minX + floor((buttonFrame.width - installLayout.size.width) / 2.0), y: buttonFrame.minY + floor((buttonFrame.height - installLayout.size.height) / 2.0) + 1.0), size: installLayout.size)
strongSelf.installButtonNode.frame = buttonFrame
if item.installed {
strongSelf.installButtonNode.isHidden = true
strongSelf.installBackgroundNode.isHidden = true
strongSelf.installTextNode.isHidden = true
} else {
strongSelf.installButtonNode.isHidden = false
strongSelf.installBackgroundNode.isHidden = false
strongSelf.installTextNode.isHidden = false
}
let titleFrame = CGRect(origin: CGPoint(x: params.leftInset + leftInset, y: 2.0), size: titleLayout.size)
strongSelf.titleNode.frame = titleFrame
strongSelf.descriptionNode.frame = CGRect(origin: CGPoint(x: params.leftInset + leftInset, y: 23.0), size: descriptionLayout.size)
if item.unread {
strongSelf.unreadNode.isHidden = false
} else {
strongSelf.unreadNode.isHidden = true
}
if let image = unreadImage {
strongSelf.unreadNode.image = image
strongSelf.unreadNode.frame = CGRect(origin: CGPoint(x: titleFrame.maxX + 2.0, y: titleFrame.minY + 7.0), size: image.size)
}
let sideInset: CGFloat = 2.0
let availableWidth = params.width - params.leftInset - params.rightInset - sideInset * 2.0
var itemSide: CGFloat = floor(availableWidth / 5.0)
itemSide = min(itemSide, 75.0)
let itemSize = CGSize(width: itemSide, height: itemSide)
var offset = sideInset
let itemSpacing = (max(0, availableWidth - 5.0 * itemSide - sideInset * 2.0)) / 4.0
let isVisible = strongSelf.visibility != .none
for i in 0 ..< topItems.count {
let file = topItems[i].file
let node: TrendingTopItemNode
if i < strongSelf.itemNodes.count {
node = strongSelf.itemNodes[i]
} else {
node = TrendingTopItemNode()
node.visibility = isVisible
strongSelf.itemNodes.append(node)
strongSelf.addSubnode(node)
}
if file.fileId != node.file?.fileId {
node.setup(account: item.account, item: topItems[i], itemSize: itemSize, synchronousLoads: synchronousLoads)
}
if let dimensions = file.dimensions {
let imageSize = dimensions.cgSize.aspectFitted(itemSize)
node.frame = CGRect(origin: CGPoint(x: offset, y: 48.0), size: imageSize)
offset += itemSize.width + itemSpacing
}
}
if topItems.count < strongSelf.itemNodes.count {
for i in (topItems.count ..< strongSelf.itemNodes.count).reversed() {
strongSelf.itemNodes[i].removeFromSupernode()
strongSelf.itemNodes.remove(at: i)
}
}
strongSelf.updatePreviewing(animated: false)
}
})
}
}
override func animateInsertion(_ currentTimestamp: Double, duration: Double, short: Bool) {
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.4)
}
override func animateRemoved(_ currentTimestamp: Double, duration: Double) {
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false)
}
@objc func installPressed() {
if let item = self.item {
item.interaction.installPack(item.info)
}
}
@objc func tapGesture(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state {
if let item = self.item {
item.interaction.openPack(item.info)
}
}
}
func itemAt(point: CGPoint) -> (ASDisplayNode, StickerPackItem)? {
guard let item = self.item else {
return nil
}
var index = 0
for itemNode in self.itemNodes {
if itemNode.frame.contains(point), index < item.topItems.count {
return (itemNode, item.topItems[index])
}
index += 1
}
return nil
}
func updatePreviewing(animated: Bool) {
guard let item = self.item else {
return
}
var index = 0
for itemNode in self.itemNodes {
if index < item.topItems.count {
let isPreviewing = item.interaction.getItemIsPreviewed(item.topItems[index])
itemNode.updatePreviewing(animated: animated, isPreviewing: isPreviewing)
}
index += 1
}
}
} }

View File

@ -302,6 +302,16 @@ class StickerPaneSearchGlobalItemNode: GridItemNode {
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:)))) self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
} }
private var absoluteLocation: (CGRect, CGSize)?
override public func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
self.absoluteLocation = (rect, containerSize)
for node in self.itemNodes {
let nodeRect = CGRect(origin: CGPoint(x: rect.minX + node.frame.minX, y: rect.minY + node.frame.minY), size: node.frame.size)
node.updateAbsoluteRect(nodeRect, within: containerSize)
}
}
func setup(item: StickerPaneSearchGlobalItem) { func setup(item: StickerPaneSearchGlobalItem) {
if item.topItems.count < Int(item.info.count) && item.topItems.count < 5 && self.item?.info.id != item.info.id { if item.topItems.count < Int(item.info.count) && item.topItems.count < 5 && self.item?.info.id != item.info.id {
self.preloadDisposable.set(preloadedFeaturedStickerSet(network: item.account.network, postbox: item.account.postbox, id: item.info.id).start()) self.preloadDisposable.set(preloadedFeaturedStickerSet(network: item.account.network, postbox: item.account.postbox, id: item.info.id).start())
@ -451,11 +461,17 @@ class StickerPaneSearchGlobalItemNode: GridItemNode {
if file.fileId != node.file?.fileId { if file.fileId != node.file?.fileId {
node.setup(account: item.account, item: topItems[i], itemSize: itemSize, synchronousLoads: synchronousLoads) node.setup(account: item.account, item: topItems[i], itemSize: itemSize, synchronousLoads: synchronousLoads)
} }
if item.theme !== node.theme {
node.update(theme: item.theme, listAppearance: item.listAppearance)
}
if let dimensions = file.dimensions { if let dimensions = file.dimensions {
let imageSize = dimensions.cgSize.aspectFitted(itemSize) let imageSize = dimensions.cgSize.aspectFitted(itemSize)
node.frame = CGRect(origin: CGPoint(x: offset, y: 48.0 + topOffset), size: imageSize) node.frame = CGRect(origin: CGPoint(x: offset, y: 48.0 + topOffset), size: imageSize)
offset += itemSize.width + itemSpacing offset += itemSize.width + itemSpacing
} }
if let (rect, size) = strongSelf.absoluteLocation {
strongSelf.updateAbsoluteRect(rect, within: size)
}
} }
if topItems.count < strongSelf.itemNodes.count { if topItems.count < strongSelf.itemNodes.count {