subtext label implemented
This commit is contained in:
parent
88defbc75c
commit
870658b4c1
@ -9,18 +9,20 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtocol {
|
open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtocol {
|
||||||
|
|
||||||
public let bodyLabel = Label.commonLabelB2(true)
|
public let bodyLabel = Label(frame: .zero)
|
||||||
|
public let subTextLabel = Label(frame: .zero)
|
||||||
public let lineView = View(frame: .zero)
|
public let lineView = View(frame: .zero)
|
||||||
var bottomView = MVMCoreUICommonViewsUtility.commonView()
|
var bottomView = MVMCoreUICommonViewsUtility.commonView()
|
||||||
public var lineViewHeight: NSLayoutConstraint?
|
public var lineViewHeight: NSLayoutConstraint?
|
||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
|
var boxModel: RadioBoxModel!
|
||||||
|
|
||||||
open override var isSelected: Bool{
|
open override var isSelected: Bool{
|
||||||
didSet{
|
didSet{
|
||||||
self.lineViewHeight?.constant = self.isSelected ? 4.0 : 0
|
if let shapeLayer = self.bottomView.layer.sublayers?.filter({$0.name == "outofstock"}).first as? CAShapeLayer {
|
||||||
UIView.animate(withDuration: 0.5) {
|
shapeLayer.strokeColor = isSelected ? UIColor.black.cgColor : UIColor.mfGet(forHex: "#747676").cgColor
|
||||||
self.layoutIfNeeded()
|
|
||||||
}
|
}
|
||||||
|
self.lineViewHeight?.constant = self.isSelected ? 4.0 : 0
|
||||||
self.bottomView.layer.sublayers?.filter({$0.name == "border"}).forEach({$0.removeFromSuperlayer()})
|
self.bottomView.layer.sublayers?.filter({$0.name == "border"}).forEach({$0.removeFromSuperlayer()})
|
||||||
if(self.isSelected){
|
if(self.isSelected){
|
||||||
self.bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
self.bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
||||||
@ -28,8 +30,11 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
self.bottomView.layer.addBorder(edge: .right, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
self.bottomView.layer.addBorder(edge: .right, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.addBordertoView()
|
self.addBordertoView("#747676")
|
||||||
}
|
}
|
||||||
|
UIView.animate(withDuration: 0.5) {
|
||||||
|
self.layoutIfNeeded()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +82,18 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
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
|
|
||||||
|
subTextLabel.numberOfLines = 1
|
||||||
|
bottomView.addSubview(subTextLabel)
|
||||||
|
NSLayoutConstraint.constraintPinSubview(subTextLabel, pinTop: false, topConstant:0 , pinBottom: false, bottomConstant: 0, pinLeft: true, leftConstant: 12, pinRight: true, rightConstant: 12)
|
||||||
|
subTextLabel.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true
|
||||||
|
subTextLabel.topAnchor.constraint(equalTo: bodyLabel.bottomAnchor, constant: 2).isActive = true
|
||||||
|
|
||||||
|
subTextLabel.font = MFFonts.mfFontTXRegular(11.0)
|
||||||
|
bodyLabel.font = MFFonts.mfFontTXRegular(13.0)
|
||||||
|
subTextLabel.textColor = UIColor.mfGet(forHex: "#747676")
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateView(_ size: CGFloat) {
|
public func updateView(_ size: CGFloat) {
|
||||||
@ -85,15 +101,16 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
self.bottomView.setNeedsLayout()
|
self.bottomView.setNeedsLayout()
|
||||||
self.bottomView.layer.sublayers?.filter({$0.name == "border"}).forEach({$0.removeFromSuperlayer()})
|
self.bottomView.layer.sublayers?.filter({$0.name == "border"}).forEach({$0.removeFromSuperlayer()})
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
self?.addBordertoView()
|
guard let self = self else { return }
|
||||||
|
self.addBordertoView(self.boxModel.enabled ? "#747676" : "#D8DADA")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addBordertoView(){
|
private func addBordertoView(_ color:String){
|
||||||
bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#747676"), thickness: 1.0)
|
bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: color), 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: color), 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: color), 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: color), thickness: 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addOutOfStockLine(){
|
private func addOutOfStockLine(){
|
||||||
@ -103,20 +120,22 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
let shapeLayer = CAShapeLayer()
|
let shapeLayer = CAShapeLayer()
|
||||||
shapeLayer.name = "outofstock"
|
shapeLayer.name = "outofstock"
|
||||||
shapeLayer.path = path.cgPath
|
shapeLayer.path = path.cgPath
|
||||||
shapeLayer.strokeColor = UIColor.darkGray.cgColor
|
shapeLayer.strokeColor = self.boxModel.enabled ? UIColor.black.cgColor : UIColor.mfGet(forHex: "#D8DADA").cgColor
|
||||||
shapeLayer.lineWidth = 0.5
|
shapeLayer.lineWidth = 0.5
|
||||||
bottomView.layer.addSublayer(shapeLayer)
|
bottomView.layer.addSublayer(shapeLayer)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
guard let collectionModel = model as? RadioBoxModel else { return }
|
guard let collectionModel = model as? RadioBoxModel else { return }
|
||||||
|
boxModel = collectionModel
|
||||||
if let backgroundColor = collectionModel.backgroundColor {
|
if let backgroundColor = collectionModel.backgroundColor {
|
||||||
bottomView.backgroundColor = backgroundColor.uiColor
|
bottomView.backgroundColor = backgroundColor.uiColor
|
||||||
}
|
}
|
||||||
self.isUserInteractionEnabled = collectionModel.enabled
|
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
|
subTextLabel.text = collectionModel.subText
|
||||||
|
// isSelected = collectionModel.selected
|
||||||
fieldValue = collectionModel.fieldValue
|
fieldValue = collectionModel.fieldValue
|
||||||
isOutOfStock = collectionModel.strikethrough
|
isOutOfStock = collectionModel.strikethrough
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import Foundation
|
|||||||
@objcMembers public class RadioBoxModel: MoleculeModelProtocol {
|
@objcMembers public class RadioBoxModel: MoleculeModelProtocol {
|
||||||
public static var identifier: String = "radioBox"
|
public static var identifier: String = "radioBox"
|
||||||
public var text: String
|
public var text: String
|
||||||
|
public var subText: 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
|
||||||
@ -20,6 +21,7 @@ import Foundation
|
|||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case text
|
case text
|
||||||
|
case subText
|
||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case selected
|
case selected
|
||||||
@ -31,6 +33,7 @@ import Foundation
|
|||||||
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)
|
||||||
|
subText = try typeContainer.decodeIfPresent(String.self, forKey: .subText)
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) {
|
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) {
|
||||||
selectedAccentColor = color
|
selectedAccentColor = color
|
||||||
}
|
}
|
||||||
@ -52,6 +55,8 @@ import Foundation
|
|||||||
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(text, forKey: .text)
|
||||||
|
try container.encodeIfPresent(subText, forKey: .subText)
|
||||||
try container.encodeIfPresent(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)
|
||||||
|
|||||||
@ -56,9 +56,15 @@ open class RadioBoxes: View {
|
|||||||
@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()
|
guard let self = self else { return }
|
||||||
self?.collectionView.layoutIfNeeded()
|
self.setNeedsDisplay()
|
||||||
self?.collectionView.reloadData()
|
self.collectionView.layoutIfNeeded()
|
||||||
|
self.collectionView.reloadData()
|
||||||
|
guard let firstSelectedIndex = self.boxes?.firstIndex(where: {$0.selected == true}) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.collectionView.selectItem(at: IndexPath(item: firstSelectedIndex, section: 0), animated: true, scrollPosition: .centeredHorizontally)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user