Merge branch 'develop' into feature/radio_swatches
This commit is contained in:
commit
fdd22f10e3
@ -60,7 +60,7 @@ open class RadioBox: Control {
|
|||||||
|
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let model = model as? RadioBoxModel else { return }
|
guard let model = model as? RadioBoxModel else { return }
|
||||||
isSelected = model.selected
|
isSelected = model.selected
|
||||||
@ -69,6 +69,15 @@ open class RadioBox: Control {
|
|||||||
subTextLabel.text = model.subText
|
subTextLabel.text = model.subText
|
||||||
isOutOfStock = model.strikethrough
|
isOutOfStock = model.strikethrough
|
||||||
subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0
|
subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0
|
||||||
|
if let color = model.selectedAccentColor?.uiColor {
|
||||||
|
accentColor = color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open override func reset() {
|
||||||
|
super.reset()
|
||||||
|
backgroundColor = .white
|
||||||
|
accentColor = .mvmRed
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - State Handling
|
// MARK: - State Handling
|
||||||
@ -134,7 +143,7 @@ open class RadioBox: Control {
|
|||||||
|
|
||||||
let topLineLayer = CAShapeLayer()
|
let topLineLayer = CAShapeLayer()
|
||||||
topLineLayer.fillColor = nil
|
topLineLayer.fillColor = nil
|
||||||
topLineLayer.strokeColor = UIColor.mvmRed.cgColor
|
topLineLayer.strokeColor = accentColor.cgColor
|
||||||
topLineLayer.lineWidth = 4
|
topLineLayer.lineWidth = 4
|
||||||
topLineLayer.path = topLinePath.cgPath
|
topLineLayer.path = topLinePath.cgPath
|
||||||
layer.addSublayer(topLineLayer)
|
layer.addSublayer(topLineLayer)
|
||||||
|
|||||||
@ -8,7 +8,12 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
open class RadioBoxCollectionViewCell: CollectionViewCell {
|
open class RadioBoxCollectionViewCell: CollectionViewCell {
|
||||||
let radioBox = RadioBox()
|
public let radioBox = RadioBox()
|
||||||
|
|
||||||
|
open override func reset() {
|
||||||
|
super.reset()
|
||||||
|
backgroundColor = .clear
|
||||||
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import Foundation
|
|||||||
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 subText: String?
|
||||||
public var backgroundColor: Color? = Color(uiColor: .white)
|
public var backgroundColor: Color?
|
||||||
public var selectedAccentColor = Color(uiColor: .mvmRed)
|
public var selectedAccentColor: Color?
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
public var enabled: Bool = true
|
public var enabled: Bool = true
|
||||||
public var strikethrough: Bool = false
|
public var strikethrough: Bool = false
|
||||||
@ -34,12 +34,8 @@ import Foundation
|
|||||||
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)
|
subText = try typeContainer.decodeIfPresent(String.self, forKey: .subText)
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) {
|
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
||||||
selectedAccentColor = color
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
}
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) {
|
|
||||||
backgroundColor = color
|
|
||||||
}
|
|
||||||
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
||||||
selected = isSelected
|
selected = isSelected
|
||||||
}
|
}
|
||||||
@ -58,7 +54,7 @@ import Foundation
|
|||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(text, forKey: .text)
|
try container.encode(text, forKey: .text)
|
||||||
try container.encodeIfPresent(subText, forKey: .subText)
|
try container.encodeIfPresent(subText, forKey: .subText)
|
||||||
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.encode(selected, forKey: .selected)
|
try container.encode(selected, forKey: .selected)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
|
|||||||
@ -16,7 +16,10 @@ open class RadioBoxes: View {
|
|||||||
private let boxHeight: CGFloat = 64.0
|
private let boxHeight: CGFloat = 64.0
|
||||||
private let itemSpacing: CGFloat = 8.0
|
private let itemSpacing: CGFloat = 8.0
|
||||||
private var numberOfColumns: CGFloat = 2.0
|
private var numberOfColumns: CGFloat = 2.0
|
||||||
|
private var radioBoxesModel: RadioBoxesModel? {
|
||||||
|
return model as? RadioBoxesModel
|
||||||
|
}
|
||||||
|
|
||||||
private var delegateObject: MVMCoreUIDelegateObject?
|
private var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
|
||||||
/// The models for the molecules.
|
/// The models for the molecules.
|
||||||
@ -43,7 +46,7 @@ open class RadioBoxes: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
@ -118,7 +121,16 @@ extension RadioBoxes: UICollectionViewDataSource {
|
|||||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
|
cell.reset()
|
||||||
cell.radioBox.isUserInteractionEnabled = false
|
cell.radioBox.isUserInteractionEnabled = false
|
||||||
|
|
||||||
|
if let color = radioBoxesModel?.boxesColor {
|
||||||
|
cell.radioBox.backgroundColor = color.uiColor
|
||||||
|
}
|
||||||
|
if let color = radioBoxesModel?.selectedAccentColor {
|
||||||
|
cell.radioBox.accentColor = color.uiColor
|
||||||
|
}
|
||||||
|
|
||||||
cell.set(with: molecule, delegateObject, nil)
|
cell.set(with: molecule, delegateObject, nil)
|
||||||
cell.updateView(size ?? collectionView.bounds.width)
|
cell.updateView(size ?? collectionView.bounds.width)
|
||||||
if molecule.selected {
|
if molecule.selected {
|
||||||
@ -130,18 +142,18 @@ extension RadioBoxes: UICollectionViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension RadioBoxes: UICollectionViewDelegate {
|
extension RadioBoxes: UICollectionViewDelegate {
|
||||||
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||||
guard let molecule = boxes?[indexPath.row] else { return false }
|
guard let molecule = boxes?[indexPath.row] else { return false }
|
||||||
return molecule.enabled
|
return molecule.enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return }
|
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return }
|
||||||
cell.radioBox.selectBox()
|
cell.radioBox.selectBox()
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
||||||
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return }
|
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return }
|
||||||
cell.radioBox.deselectBox()
|
cell.radioBox.deselectBox()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,10 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
@objcMembers public class RadioBoxesModel: MoleculeModelProtocol, FormFieldProtocol {
|
@objcMembers public class RadioBoxesModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||||
public static var identifier: String = "radioBoxes"
|
public static var identifier: String = "radioBoxes"
|
||||||
|
public var boxes: [RadioBoxModel]
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var selectedAccentColor: Color?
|
public var selectedAccentColor: Color?
|
||||||
public var boxes: [RadioBoxModel]
|
public var boxesColor: Color?
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
public var baseValue: AnyHashable?
|
public var baseValue: AnyHashable?
|
||||||
@ -28,6 +29,7 @@ import Foundation
|
|||||||
case moleculeName
|
case moleculeName
|
||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case boxesColor
|
||||||
case boxes
|
case boxes
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
@ -37,6 +39,7 @@ import Foundation
|
|||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
boxesColor = try typeContainer.decodeIfPresent(Color.self, forKey: .boxesColor)
|
||||||
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)
|
||||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user