[WIP] Premium setup

This commit is contained in:
Isaac
2024-03-15 15:10:58 +04:00
parent ae3ee3d063
commit d8026b4009
30 changed files with 1495 additions and 309 deletions

View File

@@ -5,11 +5,13 @@ public final class Rectangle: Component {
private let color: UIColor
private let width: CGFloat?
private let height: CGFloat?
private let tag: NSObject?
public init(color: UIColor, width: CGFloat? = nil, height: CGFloat? = nil) {
public init(color: UIColor, width: CGFloat? = nil, height: CGFloat? = nil, tag: NSObject? = nil) {
self.color = color
self.width = width
self.height = height
self.tag = tag
}
public static func ==(lhs: Rectangle, rhs: Rectangle) -> Bool {
@@ -25,7 +27,33 @@ public final class Rectangle: Component {
return true
}
public func update(view: UIView, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
public final class View: UIView, ComponentTaggedView {
fileprivate var componentTag: NSObject?
override public init(frame: CGRect) {
super.init(frame: frame)
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func matches(tag: Any) -> Bool {
if let componentTag = self.componentTag {
let tag = tag as AnyObject
if componentTag === tag {
return true
}
}
return false
}
}
public func makeView() -> View {
return View(frame: CGRect())
}
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
var size = availableSize
if let width = self.width {
size.width = min(size.width, width)
@@ -35,6 +63,7 @@ public final class Rectangle: Component {
}
view.backgroundColor = self.color
view.componentTag = self.tag
return size
}