Swiftgram/submodules/TelegramUI/TelegramUI/InstantPageTileNode.swift
Peter b317aab568 Add 'submodules/TelegramUI/' from commit 'fa3ac0b61a27c8dd3296518a15891a6f9750cbf2'
git-subtree-dir: submodules/TelegramUI
git-subtree-mainline: 5c1613d1048026b9e00a6ce753775cef87eb53fa
git-subtree-split: fa3ac0b61a27c8dd3296518a15891a6f9750cbf2
2019-06-11 19:00:46 +01:00

49 lines
1.5 KiB
Swift

import Foundation
import UIKit
import AsyncDisplayKit
private final class InstantPageTileNodeParameters: NSObject {
let tile: InstantPageTile
let backgroundColor: UIColor
init(tile: InstantPageTile, backgroundColor: UIColor) {
self.tile = tile
self.backgroundColor = backgroundColor
super.init()
}
}
final class InstantPageTileNode: ASDisplayNode {
private let tile: InstantPageTile
init(tile: InstantPageTile, backgroundColor: UIColor) {
self.tile = tile
super.init()
self.isLayerBacked = true
self.isOpaque = false
self.backgroundColor = backgroundColor
}
override func drawParameters(forAsyncLayer layer: _ASDisplayLayer) -> NSObjectProtocol? {
return InstantPageTileNodeParameters(tile: self.tile, backgroundColor: self.backgroundColor ?? UIColor.white)
}
@objc override public class func draw(_ bounds: CGRect, withParameters parameters: Any?, isCancelled: () -> Bool, isRasterizing: Bool) {
let context = UIGraphicsGetCurrentContext()!
if let parameters = parameters as? InstantPageTileNodeParameters {
if !isRasterizing {
context.setBlendMode(.copy)
context.setFillColor(parameters.backgroundColor.cgColor)
context.fill(bounds)
}
parameters.tile.draw(context: context)
}
}
}