border changes updated
This commit is contained in:
parent
3b8fd4167c
commit
96115b7a5d
@ -8,28 +8,37 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtocol {
|
open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtocol {
|
||||||
|
|
||||||
public let bodyLabel = Label.commonLabelB2(true)
|
public let bodyLabel = Label.commonLabelB2(true)
|
||||||
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?
|
||||||
|
|
||||||
|
|
||||||
open override var isSelected: Bool{
|
open override var isSelected: Bool{
|
||||||
didSet{
|
didSet{
|
||||||
lineViewHeight?.constant = isSelected ? 4.0 : 0
|
self.lineViewHeight?.constant = self.isSelected ? 4.0 : 0
|
||||||
bottomView.layer.borderColor = isSelected ? UIColor.mfGet(forHex: "#0000").cgColor:UIColor.mfGet(forHex: "#747676").cgColor
|
self.bottomView.layer.sublayers?.filter({$0.name == "border"}).forEach({$0.removeFromSuperlayer()})
|
||||||
|
if(self.isSelected){
|
||||||
|
self.bottomView.layer.addBorder(edge: .bottom, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
||||||
|
self.bottomView.layer.addBorder(edge: .left, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
||||||
|
self.bottomView.layer.addBorder(edge: .right, color: UIColor.mfGet(forHex: "#0000"), thickness: 1.0)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.addBordertoView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
open override func layoutSubviews() {
|
||||||
|
super.layoutSubviews()
|
||||||
|
addBordertoView()
|
||||||
|
|
||||||
|
}
|
||||||
public required init?(coder aDecoder: NSCoder) {
|
public required init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
setupView()
|
setupView()
|
||||||
@ -44,7 +53,6 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
insetsLayoutMarginsFromSafeArea = false
|
insetsLayoutMarginsFromSafeArea = false
|
||||||
contentView.insetsLayoutMarginsFromSafeArea = false
|
contentView.insetsLayoutMarginsFromSafeArea = false
|
||||||
contentView.preservesSuperviewLayoutMargins = false
|
contentView.preservesSuperviewLayoutMargins = false
|
||||||
|
|
||||||
contentView.addSubview(bottomView)
|
contentView.addSubview(bottomView)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomView)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomView)
|
||||||
|
|
||||||
@ -54,34 +62,58 @@ open class RadioBoxCollectionViewCell: UICollectionViewCell, MoleculeViewProtoco
|
|||||||
lineViewHeight = lineView.heightAnchor.constraint(equalToConstant: 0)
|
lineViewHeight = lineView.heightAnchor.constraint(equalToConstant: 0)
|
||||||
lineViewHeight?.isActive = true
|
lineViewHeight?.isActive = true
|
||||||
|
|
||||||
|
|
||||||
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
|
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
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(greaterThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true
|
bodyLabel.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor, constant: -12.0).isActive = true
|
||||||
|
|
||||||
bottomView.layer.borderWidth = 1.0
|
|
||||||
bottomView.layer.borderColor = UIColor.mfGet(forHex: "#747676").cgColor
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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 }
|
||||||
|
|
||||||
if let backgroundColor = collectionModel.backgroundColor {
|
if let backgroundColor = collectionModel.backgroundColor {
|
||||||
self.bottomView.backgroundColor = backgroundColor.uiColor
|
self.bottomView.backgroundColor = backgroundColor.uiColor
|
||||||
}
|
}
|
||||||
// self.bottomView.backgroundColor = .red
|
|
||||||
lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor
|
lineView.backgroundColor = collectionModel.selectedAccentColor?.uiColor
|
||||||
bodyLabel.text = collectionModel.text
|
bodyLabel.text = collectionModel.text
|
||||||
|
isSelected = collectionModel.selected ?? false
|
||||||
|
fieldValue = collectionModel.fieldValue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
extension CALayer {
|
||||||
|
|
||||||
|
func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) {
|
||||||
|
|
||||||
|
let border = CALayer()
|
||||||
|
border.name = "border"
|
||||||
|
switch edge {
|
||||||
|
case UIRectEdge.top:
|
||||||
|
border.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: thickness)
|
||||||
|
break
|
||||||
|
case UIRectEdge.bottom:
|
||||||
|
border.frame = CGRect(x: 0, y: self.frame.height - thickness, width: self.frame.width, height: thickness)
|
||||||
|
break
|
||||||
|
case UIRectEdge.left:
|
||||||
|
border.frame = CGRect(x: 0, y: 0, width: thickness, height: self.frame.height)
|
||||||
|
break
|
||||||
|
case UIRectEdge.right:
|
||||||
|
border.frame = CGRect(x: self.frame.width - thickness, y: 0, width: thickness, height: self.frame.height)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
border.backgroundColor = color.cgColor;
|
||||||
|
self.addSublayer(border)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,9 @@ import Foundation
|
|||||||
public static var identifier: String = "radioBox"
|
public static var identifier: String = "radioBox"
|
||||||
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? = Color(uiColor: .red)
|
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 fieldValue: String?
|
public var fieldValue: String?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -21,6 +22,7 @@ import Foundation
|
|||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case selected
|
case selected
|
||||||
|
case strikethrough
|
||||||
case fieldValue
|
case fieldValue
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -38,6 +40,9 @@ 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 isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
||||||
|
strikethrough = isStrikeTrough
|
||||||
|
}
|
||||||
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -48,6 +53,7 @@ import Foundation
|
|||||||
try container.encode(selectedAccentColor, forKey: .selectedAccentColor)
|
try container.encode(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(strikethrough, forKey: .strikethrough)
|
||||||
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
|
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,21 +7,23 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
open class RadioBoxes: View {
|
|
||||||
|
|
||||||
|
open class RadioBoxes: View {
|
||||||
|
|
||||||
public let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
|
public let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
|
||||||
|
|
||||||
/// The models for the molecules.
|
/// The models for the molecules.
|
||||||
var molecules: [MoleculeModelProtocol]?
|
var boxes: [RadioBoxModel]?
|
||||||
|
public var fieldKey: String?
|
||||||
|
public var groupName: String?
|
||||||
|
public var enabled: Bool?
|
||||||
|
|
||||||
|
|
||||||
/// The height of the carousel. Default is 300.
|
|
||||||
public var collectionViewHeight: NSLayoutConstraint?
|
public var collectionViewHeight: NSLayoutConstraint?
|
||||||
|
private let boxWidth: Double = 151.0
|
||||||
public var delegateObject: MVMCoreUIDelegateObject?
|
private let boxHeight: Double = 64.0
|
||||||
|
private let itemSpacing: Double = 10.0
|
||||||
|
private let leadingSpacing: Double = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
@ -35,22 +37,21 @@ open class RadioBoxes: View {
|
|||||||
collectionView.backgroundColor = .clear
|
collectionView.backgroundColor = .clear
|
||||||
collectionView.isAccessibilityElement = false
|
collectionView.isAccessibilityElement = false
|
||||||
addSubview(collectionView)
|
addSubview(collectionView)
|
||||||
|
NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)
|
||||||
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300)
|
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300)
|
||||||
collectionViewHeight?.isActive = true
|
collectionViewHeight?.isActive = true
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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]?) {
|
||||||
self.delegateObject = delegateObject
|
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let radioBoxesModel = model as? RadioBoxesModel else { return }
|
guard let radioBoxesModel = model as? RadioBoxesModel else { return }
|
||||||
backgroundColor = .white
|
backgroundColor = radioBoxesModel.backgroundColor?.uiColor
|
||||||
|
fieldKey = radioBoxesModel.fieldKey
|
||||||
|
groupName = radioBoxesModel.groupName
|
||||||
|
enabled = radioBoxesModel.enabled
|
||||||
registerCells()
|
registerCells()
|
||||||
setupLayout(with: radioBoxesModel)
|
setupLayout(with: radioBoxesModel)
|
||||||
prepareMolecules(with: radioBoxesModel)
|
prepareMolecules(with: radioBoxesModel)
|
||||||
@ -59,64 +60,54 @@ open class RadioBoxes: View {
|
|||||||
|
|
||||||
// MARK: - JSON Setters
|
// MARK: - JSON Setters
|
||||||
/// Updates the layout being used
|
/// Updates the layout being used
|
||||||
|
|
||||||
func setupLayout(with carouselModel: RadioBoxesModel?) {
|
func setupLayout(with carouselModel: RadioBoxesModel?) {
|
||||||
let layout = UICollectionViewFlowLayout()
|
let layout = UICollectionViewFlowLayout()
|
||||||
layout.scrollDirection = .vertical
|
layout.scrollDirection = .vertical
|
||||||
|
layout.sectionInset = UIEdgeInsets.init(top: CGFloat(leadingSpacing), left: CGFloat(leadingSpacing), bottom: CGFloat(leadingSpacing), right: CGFloat(leadingSpacing))
|
||||||
layout.minimumLineSpacing = 10
|
layout.minimumLineSpacing = 10
|
||||||
layout.minimumInteritemSpacing = 10
|
layout.minimumInteritemSpacing = 10
|
||||||
collectionView.collectionViewLayout = layout
|
collectionView.collectionViewLayout = layout
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareMolecules(with radioBoxesModel: RadioBoxesModel?) {
|
func prepareMolecules(with radioBoxesModel: RadioBoxesModel?) {
|
||||||
guard let newMolecules = radioBoxesModel?.boxes else {
|
guard let newMolecules = radioBoxesModel?.boxes else {
|
||||||
molecules = nil
|
boxes = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
molecules = newMolecules
|
boxes = newMolecules
|
||||||
collectionView.reloadData()
|
let height = Double(round(Double((boxes?.count ?? Int(0.0)))/2.0))*(boxHeight+10.0)
|
||||||
|
collectionViewHeight?.constant = CGFloat(height)
|
||||||
|
collectionViewHeight?.isActive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Convenience
|
|
||||||
/// Returns the (identifier, class) of the molecule for the given map.
|
|
||||||
func getMoleculeInfo(with molecule: MoleculeModelProtocol, delegateObject: MVMCoreUIDelegateObject?) -> (identifier: String, class: AnyClass, molecule: MoleculeModelProtocol)? {
|
|
||||||
guard let className = MoleculeObjectMapping.shared()?.getMoleculeClass(molecule) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return (className.nameForReuse(with: molecule, delegateObject) ?? molecule.moleculeName, className, molecule)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
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 = (collectionView.bounds.width - 30)/2
|
let itemWidth = (Double(collectionView.bounds.width) - itemSpacing)/2
|
||||||
return CGSize(width: itemWidth, height: 64)
|
return CGSize(width: CGFloat(150.5), height: CGFloat(boxHeight))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RadioBoxes: UICollectionViewDataSource {
|
extension RadioBoxes: UICollectionViewDataSource {
|
||||||
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||||
return molecules?.count ?? 0
|
return boxes?.count ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
guard let molecule = molecules?[indexPath.row], let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else {
|
guard let molecule = boxes?[indexPath.row], let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else {
|
||||||
return UICollectionViewCell()
|
return UICollectionViewCell()
|
||||||
}
|
}
|
||||||
cell.set(with: molecule, delegateObject, nil)
|
cell.set(with: molecule, nil, nil)
|
||||||
(cell as? MVMCoreViewProtocol)?.updateView(collectionView.bounds.width)
|
(cell as? MVMCoreViewProtocol)?.updateView(collectionView.bounds.width)
|
||||||
|
cell.layoutIfNeeded()
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import Foundation
|
|||||||
case boxes
|
case boxes
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user