mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
import Foundation
|
|
import UIKit
|
|
|
|
public final class Rectangle: Component {
|
|
private let color: UIColor
|
|
private let width: CGFloat?
|
|
private let height: CGFloat?
|
|
|
|
public init(color: UIColor, width: CGFloat? = nil, height: CGFloat? = nil) {
|
|
self.color = color
|
|
self.width = width
|
|
self.height = height
|
|
}
|
|
|
|
public static func ==(lhs: Rectangle, rhs: Rectangle) -> Bool {
|
|
if !lhs.color.isEqual(rhs.color) {
|
|
return false
|
|
}
|
|
if lhs.width != rhs.width {
|
|
return false
|
|
}
|
|
if lhs.height != rhs.height {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
public func update(view: UIView, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
|
var size = availableSize
|
|
if let width = self.width {
|
|
size.width = min(size.width, width)
|
|
}
|
|
if let height = self.height {
|
|
size.height = min(size.height, height)
|
|
}
|
|
|
|
view.backgroundColor = self.color
|
|
|
|
return size
|
|
}
|
|
}
|