Two button remove legacy
This commit is contained in:
parent
365bbad168
commit
37228669e0
@ -41,6 +41,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
|
|||||||
self.action = action
|
self.action = action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(secondaryButtonWith title: String, action: ActionModelProtocol) {
|
||||||
|
self.title = title
|
||||||
|
self.action = action
|
||||||
|
style = .secondary
|
||||||
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
|||||||
@ -12,7 +12,8 @@ import UIKit
|
|||||||
open var primaryButton: PillButton = PillButton()
|
open var primaryButton: PillButton = PillButton()
|
||||||
open var secondaryButton: PillButton = PillButton()
|
open var secondaryButton: PillButton = PillButton()
|
||||||
private var stack = UIStackView()
|
private var stack = UIStackView()
|
||||||
|
private var equalWidthConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
}
|
}
|
||||||
@ -47,31 +48,45 @@ import UIKit
|
|||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
||||||
stack.axis = .horizontal
|
stack.axis = .horizontal
|
||||||
stack.spacing = 10
|
stack.spacing = 10
|
||||||
|
equalWidthConstraint = secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1)
|
||||||
|
equalWidthConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Stack Manipulation
|
// MARK: - Stack Manipulation
|
||||||
public func showPrimaryButton() {
|
public func showPrimaryButton() {
|
||||||
if primaryButton.superview == nil {
|
if primaryButton.superview == nil {
|
||||||
stack.addArrangedSubview(primaryButton)
|
stack.addArrangedSubview(primaryButton)
|
||||||
|
primaryButton.isHidden = false
|
||||||
|
}
|
||||||
|
if secondaryButton.superview != nil {
|
||||||
|
equalWidthConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func showSecondaryButton() {
|
public func showSecondaryButton() {
|
||||||
if secondaryButton.superview == nil {
|
if secondaryButton.superview == nil {
|
||||||
stack.addArrangedSubview(secondaryButton)
|
stack.addArrangedSubview(secondaryButton)
|
||||||
|
secondaryButton.isHidden = false
|
||||||
|
}
|
||||||
|
if primaryButton.superview != nil {
|
||||||
|
equalWidthConstraint?.isActive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func hidePrimaryButton() {
|
public func hidePrimaryButton() {
|
||||||
if primaryButton.superview != nil {
|
if primaryButton.superview != nil {
|
||||||
stack.removeArrangedSubview(primaryButton)
|
stack.removeArrangedSubview(primaryButton)
|
||||||
|
primaryButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
equalWidthConstraint?.isActive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
public func hideSecondaryButton() {
|
public func hideSecondaryButton() {
|
||||||
if secondaryButton.superview != nil {
|
if secondaryButton.superview != nil {
|
||||||
stack.removeArrangedSubview(secondaryButton)
|
stack.removeArrangedSubview(secondaryButton)
|
||||||
|
secondaryButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
equalWidthConstraint?.isActive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|||||||
@ -8,9 +8,35 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public struct TwoButtonViewModel: MoleculeModelProtocol {
|
public class TwoButtonViewModel: MoleculeModelProtocol {
|
||||||
public static var identifier: String = "twoButtonView"
|
public static var identifier: String = "twoButtonView"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var primaryButton: ButtonModel?
|
public var primaryButton: ButtonModel?
|
||||||
public var secondaryButton: ButtonModel?
|
public var secondaryButton: ButtonModel?
|
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
|
case backgroundColor
|
||||||
|
case primaryButton
|
||||||
|
case secondaryButton
|
||||||
|
}
|
||||||
|
|
||||||
|
required public init(from decoder: Decoder) throws {
|
||||||
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
primaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .primaryButton)
|
||||||
|
secondaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .secondaryButton)
|
||||||
|
// Default value
|
||||||
|
if secondaryButton?.style == nil {
|
||||||
|
secondaryButton?.style = .secondary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(primaryButton, forKey: .primaryButton)
|
||||||
|
try container.encodeIfPresent(secondaryButton, forKey: .secondaryButton)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user