alignment changes
This commit is contained in:
parent
ced8dd54e1
commit
f251b55004
@ -15,7 +15,6 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
public var lineViewHeight: NSLayoutConstraint?
|
public var lineViewHeight: NSLayoutConstraint?
|
||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
|
|
||||||
|
|
||||||
open override var isSelected: Bool{
|
open override var isSelected: Bool{
|
||||||
didSet{
|
didSet{
|
||||||
self.lineViewHeight?.constant = self.isSelected ? 4.0 : 0
|
self.lineViewHeight?.constant = self.isSelected ? 4.0 : 0
|
||||||
@ -33,23 +32,24 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var isOutofStock: Bool = false{
|
|
||||||
|
var isOutOfStock: Bool = false {
|
||||||
didSet{
|
didSet{
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let strongSelf = self else {
|
guard let self = self else { return }
|
||||||
return
|
self.bottomView.layer.sublayers?.filter({$0.name == "outofstock"}).forEach({$0.removeFromSuperlayer()})
|
||||||
}
|
if(self.isOutOfStock) {
|
||||||
strongSelf.bottomView.layer.sublayers?.filter({$0.name == "outofstock"}).forEach({$0.removeFromSuperlayer()})
|
self.addOutOfStockLine()
|
||||||
if(strongSelf.isOutofStock){
|
|
||||||
strongSelf.addOutofstockLine()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init?(coder aDecoder: NSCoder) {
|
public required init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
setupView()
|
setupView()
|
||||||
@ -68,20 +68,18 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
contentView.addSubview(bottomView)
|
contentView.addSubview(bottomView)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomView)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomView)
|
||||||
|
|
||||||
lineView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
bottomView.addSubview(lineView)
|
bottomView.addSubview(lineView)
|
||||||
NSLayoutConstraint.constraintPinSubview(lineView, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true)
|
NSLayoutConstraint.constraintPinSubview(lineView, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true)
|
||||||
lineViewHeight = lineView.heightAnchor.constraint(equalToConstant: 0)
|
lineViewHeight = lineView.heightAnchor.constraint(equalToConstant: 0)
|
||||||
lineViewHeight?.isActive = true
|
lineViewHeight?.isActive = true
|
||||||
|
|
||||||
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
|
bodyLabel.numberOfLines = 1
|
||||||
bodyLabel.numberOfLines = 0
|
|
||||||
bottomView.addSubview(bodyLabel)
|
bottomView.addSubview(bodyLabel)
|
||||||
NSLayoutConstraint.constraintPinSubview(bodyLabel, pinTop: false, topConstant:0 , pinBottom: false, bottomConstant: 0, pinLeft: true, leftConstant: 12, pinRight: true, rightConstant: 12)
|
NSLayoutConstraint.constraintPinSubview(bodyLabel, pinTop: false, topConstant:0 , pinBottom: false, bottomConstant: 0, pinLeft: true, leftConstant: 12, pinRight: true, rightConstant: 12)
|
||||||
bodyLabel.topAnchor.constraint(equalTo: lineView.bottomAnchor, constant: 12).isActive = true
|
bodyLabel.topAnchor.constraint(equalTo: lineView.bottomAnchor, constant: 12).isActive = true
|
||||||
bodyLabel.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true
|
bodyLabel.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateView(_ size: CGFloat) {
|
public func updateView(_ size: CGFloat) {
|
||||||
self.setNeedsLayout()
|
self.setNeedsLayout()
|
||||||
self.bottomView.setNeedsLayout()
|
self.bottomView.setNeedsLayout()
|
||||||
@ -89,23 +87,19 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
self?.addBordertoView()
|
self?.addBordertoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private func addBordertoView(){
|
private func addBordertoView(){
|
||||||
bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
||||||
bottomView.layer.addBorder(edge: .left, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
bottomView.layer.addBorder(edge: .left, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
||||||
bottomView.layer.addBorder(edge: .right, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
bottomView.layer.addBorder(edge: .right, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
||||||
bottomView.layer.addBorder(edge: .top, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
bottomView.layer.addBorder(edge: .top, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
||||||
}
|
}
|
||||||
private func addOutofstockLine(){
|
|
||||||
|
private func addOutOfStockLine(){
|
||||||
let path = UIBezierPath()
|
let path = UIBezierPath()
|
||||||
path.move(to: CGPoint(x: 0, y: bottomView.bounds.height))
|
path.move(to: CGPoint(x: 0, y: bottomView.bounds.height))
|
||||||
path.addLine(to: CGPoint(x: bottomView.bounds.width, y: 0))
|
path.addLine(to: CGPoint(x: bottomView.bounds.width, y: 0))
|
||||||
|
|
||||||
let shapeLayer = CAShapeLayer()
|
let shapeLayer = CAShapeLayer()
|
||||||
shapeLayer.name = "outofstock"
|
shapeLayer.name = "outofstock"
|
||||||
shapeLayer.path = path.cgPath
|
shapeLayer.path = path.cgPath
|
||||||
@ -119,11 +113,13 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
if let backgroundColor = collectionModel.backgroundColor {
|
if let backgroundColor = collectionModel.backgroundColor {
|
||||||
bottomView.backgroundColor = backgroundColor.uiColor
|
bottomView.backgroundColor = backgroundColor.uiColor
|
||||||
}
|
}
|
||||||
|
self.isUserInteractionEnabled = collectionModel.enabled
|
||||||
lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor
|
lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor
|
||||||
bodyLabel.text = collectionModel.text
|
bodyLabel.text = collectionModel.text
|
||||||
isSelected = collectionModel.selected ?? false
|
isSelected = collectionModel.selected
|
||||||
fieldValue = collectionModel.fieldValue
|
fieldValue = collectionModel.fieldValue
|
||||||
isOutofStock = collectionModel.strikethrough ?? false
|
isOutOfStock = collectionModel.strikethrough
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,5 +149,4 @@ extension CALayer {
|
|||||||
border.backgroundColor = color.cgColor;
|
border.backgroundColor = color.cgColor;
|
||||||
self.addSublayer(border)
|
self.addSublayer(border)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,9 @@ import Foundation
|
|||||||
public var text: String
|
public var text: String
|
||||||
public var backgroundColor: Color? = Color(uiColor: .white)
|
public var backgroundColor: Color? = Color(uiColor: .white)
|
||||||
public var selectedAccentColor: Color? = try? Color(colorString: "#D52B1E")
|
public var selectedAccentColor: Color? = try? Color(colorString: "#D52B1E")
|
||||||
public var selected: Bool? = false
|
public var selected: Bool = false
|
||||||
public var strikethrough: Bool? = false
|
public var enabled: Bool = true
|
||||||
|
public var strikethrough: Bool = false
|
||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -22,15 +23,14 @@ import Foundation
|
|||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case selected
|
case selected
|
||||||
|
case enabled
|
||||||
case strikethrough
|
case strikethrough
|
||||||
case fieldValue
|
case fieldValue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
text = try typeContainer.decode(String.self, forKey: .text)
|
text = try typeContainer.decode(String.self, forKey: .text)
|
||||||
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) {
|
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) {
|
||||||
selectedAccentColor = color
|
selectedAccentColor = color
|
||||||
}
|
}
|
||||||
@ -40,21 +40,23 @@ import Foundation
|
|||||||
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
||||||
selected = isSelected
|
selected = isSelected
|
||||||
}
|
}
|
||||||
|
if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
|
enabled = isEnabled
|
||||||
|
}
|
||||||
if let isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
if let isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
||||||
strikethrough = isStrikeTrough
|
strikethrough = isStrikeTrough
|
||||||
}
|
}
|
||||||
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(selectedAccentColor, forKey: .selectedAccentColor)
|
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(selected, forKey: .selected)
|
try container.encodeIfPresent(selected, forKey: .selected)
|
||||||
|
try container.encodeIfPresent(enabled, forKey: .enabled)
|
||||||
try container.encodeIfPresent(strikethrough, forKey: .strikethrough)
|
try container.encodeIfPresent(strikethrough, forKey: .strikethrough)
|
||||||
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
|
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,6 @@ open class RadioBoxes: View {
|
|||||||
var boxes: [RadioBoxModel]?
|
var boxes: [RadioBoxModel]?
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String?
|
public var groupName: String?
|
||||||
public var enabled: Bool?
|
|
||||||
|
|
||||||
public var collectionViewHeight: NSLayoutConstraint?
|
public var collectionViewHeight: NSLayoutConstraint?
|
||||||
private let boxWidth: Double = 151.0
|
private let boxWidth: Double = 151.0
|
||||||
private let boxHeight: Double = 64.0
|
private let boxHeight: Double = 64.0
|
||||||
@ -40,10 +38,8 @@ open class RadioBoxes: View {
|
|||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)
|
||||||
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300)
|
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300)
|
||||||
collectionViewHeight?.isActive = true
|
collectionViewHeight?.isActive = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
@ -51,25 +47,21 @@ open class RadioBoxes: View {
|
|||||||
backgroundColor = radioBoxesModel.backgroundColor?.uiColor
|
backgroundColor = radioBoxesModel.backgroundColor?.uiColor
|
||||||
fieldKey = radioBoxesModel.fieldKey
|
fieldKey = radioBoxesModel.fieldKey
|
||||||
groupName = radioBoxesModel.groupName
|
groupName = radioBoxesModel.groupName
|
||||||
enabled = radioBoxesModel.enabled
|
|
||||||
registerCells()
|
registerCells()
|
||||||
setupLayout(with: radioBoxesModel)
|
setupLayout(with: radioBoxesModel)
|
||||||
prepareMolecules(with: radioBoxesModel)
|
prepareMolecules(with: radioBoxesModel)
|
||||||
collectionView.reloadData()
|
collectionView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc override open func updateView(_ size: CGFloat) {
|
@objc override open func updateView(_ size: CGFloat) {
|
||||||
|
|
||||||
collectionView.collectionViewLayout.invalidateLayout()
|
collectionView.collectionViewLayout.invalidateLayout()
|
||||||
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
self?.setNeedsDisplay()
|
self?.setNeedsDisplay()
|
||||||
self?.collectionView.layoutIfNeeded()
|
self?.collectionView.layoutIfNeeded()
|
||||||
self?.collectionView.reloadData()
|
self?.collectionView.reloadData()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - JSON Setters
|
// MARK: - JSON Setters
|
||||||
/// Updates the layout being used
|
/// Updates the layout being used
|
||||||
|
|
||||||
@ -95,12 +87,10 @@ open class RadioBoxes: View {
|
|||||||
|
|
||||||
/// Registers the cells with the collection view
|
/// Registers the cells with the collection view
|
||||||
func registerCells() {
|
func registerCells() {
|
||||||
|
|
||||||
collectionView.register(RadioBoxCollectionViewCell.self, forCellWithReuseIdentifier: "RadioBoxCollectionViewCell")
|
collectionView.register(RadioBoxCollectionViewCell.self, forCellWithReuseIdentifier: "RadioBoxCollectionViewCell")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RadioBoxes: UICollectionViewDelegateFlowLayout {
|
extension RadioBoxes: UICollectionViewDelegateFlowLayout {
|
||||||
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
||||||
let itemWidth = (Double(collectionView.bounds.width) - itemSpacing)/2
|
let itemWidth = (Double(collectionView.bounds.width) - itemSpacing)/2
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import Foundation
|
|||||||
public static var identifier: String = "radioBoxes"
|
public static var identifier: String = "radioBoxes"
|
||||||
public var backgroundColor: Color? = Color(uiColor: .white)
|
public var backgroundColor: Color? = Color(uiColor: .white)
|
||||||
public var selectedAccentColor: Color? = Color(uiColor: .red)
|
public var selectedAccentColor: Color? = Color(uiColor: .red)
|
||||||
public var enabled: Bool? = true
|
|
||||||
public var boxes: [RadioBoxModel]
|
public var boxes: [RadioBoxModel]
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String?
|
public var groupName: String?
|
||||||
@ -20,7 +19,6 @@ import Foundation
|
|||||||
case moleculeName
|
case moleculeName
|
||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case enabled
|
|
||||||
case boxes
|
case boxes
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
@ -34,23 +32,17 @@ import Foundation
|
|||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
||||||
backgroundColor = color
|
backgroundColor = color
|
||||||
}
|
}
|
||||||
if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
|
||||||
enabled = isEnabled
|
|
||||||
}
|
|
||||||
boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes)
|
boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes)
|
||||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||||
groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
|
groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(selectedAccentColor, forKey: .selectedAccentColor)
|
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(enabled, forKey: .enabled)
|
|
||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user