mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
56 lines
1.8 KiB
Swift
56 lines
1.8 KiB
Swift
import Foundation
|
|
import AsyncDisplayKit
|
|
|
|
import LegacyComponents
|
|
|
|
enum CheckNodeStyle {
|
|
case plain
|
|
case overlay
|
|
}
|
|
|
|
final class CheckNode: ASDisplayNode {
|
|
private let strokeColor: UIColor
|
|
private let fillColor: UIColor
|
|
private let foregroundColor: UIColor
|
|
private let checkStyle: CheckNodeStyle
|
|
|
|
private var checkView: TGCheckButtonView?
|
|
|
|
private(set) var isChecked: Bool = false
|
|
|
|
init(strokeColor: UIColor, fillColor: UIColor, foregroundColor: UIColor, style: CheckNodeStyle) {
|
|
self.strokeColor = strokeColor
|
|
self.fillColor = fillColor
|
|
self.foregroundColor = foregroundColor
|
|
self.checkStyle = style
|
|
|
|
super.init()
|
|
}
|
|
|
|
override func didLoad() {
|
|
super.didLoad()
|
|
|
|
let style: TGCheckButtonStyle
|
|
switch self.checkStyle {
|
|
case .plain:
|
|
style = TGCheckButtonStyleDefault
|
|
case .overlay:
|
|
style = TGCheckButtonStyleMedia
|
|
}
|
|
let checkView = TGCheckButtonView(style: style, pallete: TGCheckButtonPallete(defaultBackgroundColor: self.fillColor, accentBackgroundColor: self.fillColor, defaultBorderColor: self.strokeColor, mediaBorderColor: self.strokeColor, chatBorderColor: self.strokeColor, check: self.foregroundColor, blueColor: self.fillColor, barBackgroundColor: self.fillColor))!
|
|
checkView.setSelected(true, animated: false)
|
|
checkView.layoutSubviews()
|
|
checkView.setSelected(self.isChecked, animated: false)
|
|
self.checkView = checkView
|
|
self.view.addSubview(checkView)
|
|
checkView.frame = self.bounds
|
|
}
|
|
|
|
func setIsChecked(_ isChecked: Bool, animated: Bool) {
|
|
if isChecked != self.isChecked {
|
|
self.isChecked = isChecked
|
|
self.checkView?.setSelected(isChecked, animated: animated)
|
|
}
|
|
}
|
|
}
|