mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
108 lines
3.6 KiB
Swift
108 lines
3.6 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import Display
|
|
import ComponentFlow
|
|
import TelegramCore
|
|
import EmojiStatusComponent
|
|
import AccountContext
|
|
|
|
public final class EmojiActionIconComponent: Component {
|
|
public let context: AccountContext
|
|
public let color: UIColor
|
|
public let fileId: Int64?
|
|
public let file: TelegramMediaFile?
|
|
|
|
public init(
|
|
context: AccountContext,
|
|
color: UIColor,
|
|
fileId: Int64?,
|
|
file: TelegramMediaFile?
|
|
) {
|
|
self.context = context
|
|
self.color = color
|
|
self.fileId = fileId
|
|
self.file = file
|
|
}
|
|
|
|
public static func ==(lhs: EmojiActionIconComponent, rhs: EmojiActionIconComponent) -> Bool {
|
|
if lhs.context !== rhs.context {
|
|
return false
|
|
}
|
|
if lhs.color != rhs.color {
|
|
return false
|
|
}
|
|
if lhs.fileId != rhs.fileId {
|
|
return false
|
|
}
|
|
if lhs.file != rhs.file {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
public final class View: UIView {
|
|
private var icon: ComponentView<Empty>?
|
|
|
|
func update(component: EmojiActionIconComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
|
let size = CGSize(width: 24.0, height: 24.0)
|
|
|
|
if let fileId = component.fileId {
|
|
let icon: ComponentView<Empty>
|
|
if let current = self.icon {
|
|
icon = current
|
|
} else {
|
|
icon = ComponentView()
|
|
self.icon = icon
|
|
}
|
|
let content: EmojiStatusComponent.AnimationContent
|
|
if let file = component.file {
|
|
content = .file(file: file)
|
|
} else {
|
|
content = .customEmoji(fileId: fileId)
|
|
}
|
|
let _ = icon.update(
|
|
transition: .immediate,
|
|
component: AnyComponent(EmojiStatusComponent(
|
|
context: component.context,
|
|
animationCache: component.context.animationCache,
|
|
animationRenderer: component.context.animationRenderer,
|
|
content: .animation(
|
|
content: content,
|
|
size: size,
|
|
placeholderColor: .lightGray,
|
|
themeColor: component.color,
|
|
loopMode: .forever
|
|
),
|
|
isVisibleForAnimations: false,
|
|
action: nil
|
|
)),
|
|
environment: {},
|
|
containerSize: size
|
|
)
|
|
let iconFrame = CGRect(origin: CGPoint(), size: size)
|
|
if let iconView = icon.view {
|
|
if iconView.superview == nil {
|
|
self.addSubview(iconView)
|
|
}
|
|
iconView.frame = iconFrame
|
|
}
|
|
} else {
|
|
if let icon = self.icon {
|
|
self.icon = nil
|
|
icon.view?.removeFromSuperview()
|
|
}
|
|
}
|
|
|
|
return size
|
|
}
|
|
}
|
|
|
|
public func makeView() -> View {
|
|
return View(frame: CGRect())
|
|
}
|
|
|
|
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
|
return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
|
|
}
|
|
}
|