Swiftgram/TelegramUI/SecretMediaPreviewFooterContentNode.swift
Peter Iakovlev 9bd9327502 Reduce layerBacked usage
Improved shuffling
2018-11-16 15:57:13 +04:00

45 lines
1.5 KiB
Swift

import Foundation
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import SwiftSignalKit
private let textFont = Font.regular(16.0)
final class SecretMediaPreviewFooterContentNode: GalleryFooterContentNode {
private var currentText: String?
private let textNode: ImmediateTextNode
override init() {
self.textNode = ImmediateTextNode()
self.textNode.isUserInteractionEnabled = false
self.textNode.displaysAsynchronously = false
super.init()
self.addSubnode(self.textNode)
}
func setText(_ text: String) {
if self.currentText != text {
self.currentText = text
self.textNode.attributedText = NSAttributedString(string: text, font: textFont, textColor: .white)
self.requestLayout?(.immediate)
}
}
override func updateLayout(width: CGFloat, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, contentInset: CGFloat, transition: ContainedViewLayoutTransition) -> CGFloat {
let panelHeight: CGFloat = 44.0 + bottomInset
let sideInset: CGFloat = leftInset + 8.0
let textSize = self.textNode.updateLayout(CGSize(width: width - sideInset * 2.0, height: CGFloat.greatestFiniteMagnitude))
transition.updateFrame(node: self.textNode, frame: CGRect(origin: CGPoint(x: floor((width - textSize.width) / 2.0), y: floor((44.0 - textSize.height) / 2.0)), size: textSize))
return panelHeight
}
}