Swiftgram/TelegramUI/ChatListOnlineNode.swift
Ilya Laktyushin 47d146b229 Added online statuses in chat list and share menu
Added recent stickers clearing
Added sending logs via email
Added forward recipient change on forward acccessory panel tap
Tweaked undo panel design
Various UI fixes
2019-04-09 23:49:26 +04:00

48 lines
1.7 KiB
Swift

import Foundation
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
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 = 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
}
}
})
}
}
}