mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
40 lines
2.0 KiB
Swift
40 lines
2.0 KiB
Swift
import Foundation
|
|
import AsyncDisplayKit
|
|
import Display
|
|
import TelegramCore
|
|
|
|
final class ChatLoadingNode: ASDisplayNode {
|
|
private let backgroundNode: ASImageNode
|
|
private let activityIndicator: ActivityIndicator
|
|
|
|
init(theme: PresentationTheme, chatWallpaper: TelegramWallpaper) {
|
|
self.backgroundNode = ASImageNode()
|
|
self.backgroundNode.isLayerBacked = true
|
|
self.backgroundNode.displayWithoutProcessing = true
|
|
self.backgroundNode.displaysAsynchronously = false
|
|
|
|
let graphics = PresentationResourcesChat.additionalGraphics(theme, wallpaper: chatWallpaper)
|
|
self.backgroundNode.image = graphics.chatLoadingIndicatorBackgroundImage
|
|
|
|
let serviceColor = serviceMessageColorComponents(theme: theme, wallpaper: chatWallpaper)
|
|
self.activityIndicator = ActivityIndicator(type: .custom(serviceColor.primaryText, 22.0, 2.0, false), speed: .regular)
|
|
|
|
super.init()
|
|
|
|
self.addSubnode(self.backgroundNode)
|
|
self.addSubnode(self.activityIndicator)
|
|
}
|
|
|
|
func updateLayout(size: CGSize, insets: UIEdgeInsets, transition: ContainedViewLayoutTransition) {
|
|
let displayRect = CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: size.width, height: size.height - insets.top - insets.bottom))
|
|
|
|
if let image = self.backgroundNode.image {
|
|
transition.updateFrame(node: self.backgroundNode, frame: CGRect(origin: CGPoint(x: displayRect.minX + floor((displayRect.width - image.size.width) / 2.0), y: displayRect.minY + floor((displayRect.height - image.size.height) / 2.0)), size: image.size))
|
|
}
|
|
|
|
let activitySize = self.activityIndicator.measure(size)
|
|
transition.updateFrame(node: self.activityIndicator, frame: CGRect(origin: CGPoint(x: displayRect.minX + floor((displayRect.width - activitySize.width) / 2.0), y: displayRect.minY + floor((displayRect.height - activitySize.height) / 2.0)), size: activitySize))
|
|
}
|
|
}
|
|
|