2022-02-26 02:22:10 +04:00

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
}
}