mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00

git-subtree-dir: submodules/TelegramUI git-subtree-mainline: 5c1613d1048026b9e00a6ce753775cef87eb53fa git-subtree-split: fa3ac0b61a27c8dd3296518a15891a6f9750cbf2
50 lines
1.8 KiB
Swift
50 lines
1.8 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import AsyncDisplayKit
|
|
import Display
|
|
|
|
final class ChatListOnlineNode: ASDisplayNode {
|
|
private let iconNode: ASImageNode
|
|
|
|
override init() {
|
|
self.iconNode = ASImageNode()
|
|
self.iconNode.isLayerBacked = true
|
|
self.iconNode.displaysAsynchronously = false
|
|
self.iconNode.displayWithoutProcessing = true
|
|
self.iconNode.isHidden = true
|
|
|
|
super.init()
|
|
|
|
self.isLayerBacked = true
|
|
|
|
self.addSubnode(self.iconNode)
|
|
}
|
|
|
|
func setImage(_ image: UIImage?) {
|
|
self.iconNode.image = image
|
|
}
|
|
|
|
func asyncLayout() -> (Bool) -> (CGSize, (Bool) -> Void) {
|
|
return { [weak self] online in
|
|
return (CGSize(width: 14.0, height: 14.0), { animated in
|
|
if let strongSelf = self {
|
|
strongSelf.iconNode.frame = CGRect(x: 0.0, y: 0.0, width: 14.0, height: 14.0)
|
|
|
|
if animated {
|
|
let initialScale: CGFloat = strongSelf.iconNode.isHidden ? 0.0 : CGFloat((strongSelf.iconNode.value(forKeyPath: "layer.presentationLayer.transform.scale.x") as? NSNumber)?.floatValue ?? 1.0)
|
|
let targetScale: CGFloat = online ? 1.0 : 0.0
|
|
strongSelf.iconNode.isHidden = false
|
|
strongSelf.iconNode.layer.animateScale(from: initialScale, to: targetScale, duration: 0.2, removeOnCompletion: false, completion: { [weak self] finished in
|
|
if let strongSelf = self, finished {
|
|
strongSelf.iconNode.isHidden = !online
|
|
}
|
|
})
|
|
} else {
|
|
strongSelf.iconNode.isHidden = !online
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|