mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
[WIP] Business
This commit is contained in:
@@ -11,6 +11,7 @@ public final class PlainButtonComponent: Component {
|
||||
}
|
||||
|
||||
public let content: AnyComponent<Empty>
|
||||
public let background: AnyComponent<Empty>?
|
||||
public let effectAlignment: EffectAlignment
|
||||
public let minSize: CGSize?
|
||||
public let contentInsets: UIEdgeInsets
|
||||
@@ -23,6 +24,7 @@ public final class PlainButtonComponent: Component {
|
||||
|
||||
public init(
|
||||
content: AnyComponent<Empty>,
|
||||
background: AnyComponent<Empty>? = nil,
|
||||
effectAlignment: EffectAlignment,
|
||||
minSize: CGSize? = nil,
|
||||
contentInsets: UIEdgeInsets = UIEdgeInsets(),
|
||||
@@ -34,6 +36,7 @@ public final class PlainButtonComponent: Component {
|
||||
tag: AnyObject? = nil
|
||||
) {
|
||||
self.content = content
|
||||
self.background = background
|
||||
self.effectAlignment = effectAlignment
|
||||
self.minSize = minSize
|
||||
self.contentInsets = contentInsets
|
||||
@@ -49,6 +52,9 @@ public final class PlainButtonComponent: Component {
|
||||
if lhs.content != rhs.content {
|
||||
return false
|
||||
}
|
||||
if lhs.background != rhs.background {
|
||||
return false
|
||||
}
|
||||
if lhs.effectAlignment != rhs.effectAlignment {
|
||||
return false
|
||||
}
|
||||
@@ -92,6 +98,7 @@ public final class PlainButtonComponent: Component {
|
||||
|
||||
private let contentContainer = UIView()
|
||||
private let content = ComponentView<Empty>()
|
||||
private var background: ComponentView<Empty>?
|
||||
|
||||
public var contentView: UIView? {
|
||||
return self.content.view
|
||||
@@ -243,6 +250,33 @@ public final class PlainButtonComponent: Component {
|
||||
transition.setBounds(view: self.contentContainer, bounds: CGRect(origin: CGPoint(), size: size))
|
||||
transition.setPosition(view: self.contentContainer, position: CGPoint(x: size.width * anchorX, y: size.height * 0.5))
|
||||
|
||||
if let backgroundValue = component.background {
|
||||
var backgroundTransition = transition
|
||||
let background: ComponentView<Empty>
|
||||
if let current = self.background {
|
||||
background = current
|
||||
} else {
|
||||
backgroundTransition = .immediate
|
||||
background = ComponentView()
|
||||
self.background = background
|
||||
}
|
||||
let _ = background.update(
|
||||
transition: backgroundTransition,
|
||||
component: backgroundValue,
|
||||
environment: {},
|
||||
containerSize: size
|
||||
)
|
||||
if let backgroundView = background.view {
|
||||
if backgroundView.superview == nil {
|
||||
self.contentContainer.insertSubview(backgroundView, at: 0)
|
||||
}
|
||||
backgroundTransition.setFrame(view: backgroundView, frame: CGRect(origin: CGPoint(), size: size))
|
||||
}
|
||||
} else if let background = self.background {
|
||||
self.background = nil
|
||||
background.view?.removeFromSuperview()
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user