From f251b550047d6085754a5868503471e90484efa0 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Tue, 7 Apr 2020 19:15:10 +0530 Subject: [PATCH] alignment changes --- .../Views/RadioBoxCollectionViewCell.swift | 39 ++++++++----------- .../Atomic/Atoms/Views/RadioBoxModel.swift | 16 ++++---- MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift | 14 +------ .../Atomic/Atoms/Views/RadioBoxesModel.swift | 10 +---- 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift index f29c6bb1..67068c85 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxCollectionViewCell.swift @@ -15,7 +15,6 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco public var lineViewHeight: NSLayoutConstraint? public var fieldValue: String? - open override var isSelected: Bool{ didSet{ 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{ DispatchQueue.main.async { [weak self] in - guard let strongSelf = self else { - return - } - strongSelf.bottomView.layer.sublayers?.filter({$0.name == "outofstock"}).forEach({$0.removeFromSuperlayer()}) - if(strongSelf.isOutofStock){ - strongSelf.addOutofstockLine() + guard let self = self else { return } + self.bottomView.layer.sublayers?.filter({$0.name == "outofstock"}).forEach({$0.removeFromSuperlayer()}) + if(self.isOutOfStock) { + self.addOutOfStockLine() } } } } + public override init(frame: CGRect) { super.init(frame: .zero) setupView() } + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupView() @@ -68,20 +68,18 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco contentView.addSubview(bottomView) NSLayoutConstraint.constraintPinSubview(toSuperview: bottomView) - lineView.translatesAutoresizingMaskIntoConstraints = false bottomView.addSubview(lineView) NSLayoutConstraint.constraintPinSubview(lineView, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true) lineViewHeight = lineView.heightAnchor.constraint(equalToConstant: 0) lineViewHeight?.isActive = true - bodyLabel.translatesAutoresizingMaskIntoConstraints = false - bodyLabel.numberOfLines = 0 + bodyLabel.numberOfLines = 1 bottomView.addSubview(bodyLabel) 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.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true - } + public func updateView(_ size: CGFloat) { self.setNeedsLayout() self.bottomView.setNeedsLayout() @@ -89,23 +87,19 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco DispatchQueue.main.async { [weak self] in self?.addBordertoView() } - } - - - + private func addBordertoView(){ 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: .right, 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() path.move(to: CGPoint(x: 0, y: bottomView.bounds.height)) path.addLine(to: CGPoint(x: bottomView.bounds.width, y: 0)) - let shapeLayer = CAShapeLayer() shapeLayer.name = "outofstock" shapeLayer.path = path.cgPath @@ -119,11 +113,13 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco if let backgroundColor = collectionModel.backgroundColor { bottomView.backgroundColor = backgroundColor.uiColor } + self.isUserInteractionEnabled = collectionModel.enabled lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor bodyLabel.text = collectionModel.text - isSelected = collectionModel.selected ?? false + isSelected = collectionModel.selected fieldValue = collectionModel.fieldValue - isOutofStock = collectionModel.strikethrough ?? false + isOutOfStock = collectionModel.strikethrough + } } @@ -153,5 +149,4 @@ extension CALayer { border.backgroundColor = color.cgColor; self.addSublayer(border) } - } diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift index 0e72f6e5..31f58e53 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxModel.swift @@ -12,8 +12,9 @@ import Foundation public var text: String public var backgroundColor: Color? = Color(uiColor: .white) public var selectedAccentColor: Color? = try? Color(colorString: "#D52B1E") - public var selected: Bool? = false - public var strikethrough: Bool? = false + public var selected: Bool = false + public var enabled: Bool = true + public var strikethrough: Bool = false public var fieldValue: String? private enum CodingKeys: String, CodingKey { @@ -22,15 +23,14 @@ import Foundation case selectedAccentColor case backgroundColor case selected + case enabled case strikethrough case fieldValue - } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) text = try typeContainer.decode(String.self, forKey: .text) - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) { selectedAccentColor = color } @@ -40,21 +40,23 @@ import Foundation if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) { selected = isSelected } + if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { + enabled = isEnabled + } if let isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) { strikethrough = isStrikeTrough } fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue) - } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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(selected, forKey: .selected) + try container.encodeIfPresent(enabled, forKey: .enabled) try container.encodeIfPresent(strikethrough, forKey: .strikethrough) try container.encodeIfPresent(fieldValue, forKey: .fieldValue) - } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift index 7dcd2acc..90a0d684 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxes.swift @@ -16,8 +16,6 @@ open class RadioBoxes: View { var boxes: [RadioBoxModel]? public var fieldKey: String? public var groupName: String? - public var enabled: Bool? - public var collectionViewHeight: NSLayoutConstraint? private let boxWidth: Double = 151.0 private let boxHeight: Double = 64.0 @@ -40,10 +38,8 @@ open class RadioBoxes: View { NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView) collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) collectionViewHeight?.isActive = true - } - // MARK: - MoleculeViewProtocol public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) @@ -51,25 +47,21 @@ open class RadioBoxes: View { backgroundColor = radioBoxesModel.backgroundColor?.uiColor fieldKey = radioBoxesModel.fieldKey groupName = radioBoxesModel.groupName - enabled = radioBoxesModel.enabled registerCells() setupLayout(with: radioBoxesModel) prepareMolecules(with: radioBoxesModel) collectionView.reloadData() } + @objc override open func updateView(_ size: CGFloat) { - collectionView.collectionViewLayout.invalidateLayout() - DispatchQueue.main.async { [weak self] in self?.setNeedsDisplay() self?.collectionView.layoutIfNeeded() self?.collectionView.reloadData() - } } - // MARK: - JSON Setters /// Updates the layout being used @@ -95,12 +87,10 @@ open class RadioBoxes: View { /// Registers the cells with the collection view func registerCells() { - collectionView.register(RadioBoxCollectionViewCell.self, forCellWithReuseIdentifier: "RadioBoxCollectionViewCell") } - - } + extension RadioBoxes: UICollectionViewDelegateFlowLayout { open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let itemWidth = (Double(collectionView.bounds.width) - itemSpacing)/2 diff --git a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift index ab2b4728..4e690ffa 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/RadioBoxesModel.swift @@ -11,7 +11,6 @@ import Foundation public static var identifier: String = "radioBoxes" public var backgroundColor: Color? = Color(uiColor: .white) public var selectedAccentColor: Color? = Color(uiColor: .red) - public var enabled: Bool? = true public var boxes: [RadioBoxModel] public var fieldKey: String? public var groupName: String? @@ -20,7 +19,6 @@ import Foundation case moleculeName case selectedAccentColor case backgroundColor - case enabled case boxes case fieldKey case groupName @@ -34,23 +32,17 @@ import Foundation if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { backgroundColor = color } - if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { - enabled = isEnabled - } boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) - } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) 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(enabled, forKey: .enabled) try container.encodeIfPresent(fieldKey, forKey: .fieldKey) try container.encodeIfPresent(groupName, forKey: .groupName) - } }