moved function, clean code
This commit is contained in:
parent
21a214ca89
commit
e1894bd74b
@ -64,14 +64,14 @@ open class RadioSwatchItem: Control {
|
||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
||||
//Draw the swatch
|
||||
circleLayer?.removeFromSuperlayer()
|
||||
let circle = getCircle(color: UIColor.mvmBlack, thickness: 1)
|
||||
let circle = getCircle(color: .mvmBlack, thickness: 1)
|
||||
layer.addSublayer(circle)
|
||||
circleLayer = circle
|
||||
|
||||
//Draw the strikethrough
|
||||
strikeLayer?.removeFromSuperlayer()
|
||||
if isOutOfStock {
|
||||
let line = getStrikeThrough(color: UIColor.mvmBlack, thickness: 1)
|
||||
let line = getStrikeThrough(color: .mvmBlack, thickness: 1)
|
||||
layer.addSublayer(line)
|
||||
strikeLayer = line
|
||||
}
|
||||
@ -79,7 +79,7 @@ open class RadioSwatchItem: Control {
|
||||
//Draw the selected layer
|
||||
selectedLayer?.removeFromSuperlayer()
|
||||
if isSelected {
|
||||
let outerCircle = getSelectedLayer(color: UIColor.mvmBlack, thickness: 1)
|
||||
let outerCircle = getSelectedLayer(color: .mvmBlack, thickness: 1)
|
||||
layer.addSublayer(outerCircle)
|
||||
selectedLayer = outerCircle
|
||||
bottomText.isHidden = false
|
||||
@ -104,6 +104,7 @@ open class RadioSwatchItem: Control {
|
||||
}
|
||||
|
||||
@objc open func selectSwatch() {
|
||||
guard isEnabled else { return }
|
||||
isSelected = true
|
||||
radioSwatchModel?.selected = isSelected
|
||||
layer.setNeedsDisplay()
|
||||
|
||||
@ -114,11 +114,6 @@ extension RadioSwatches: UICollectionViewDataSource {
|
||||
return swatches?.count ?? 0
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||
guard let molecule = swatches?[indexPath.row] else {return true }
|
||||
return molecule.enabled ?? true
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
guard let molecule = swatches?[indexPath.row], let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioSwatchItemCollectionViewCell", for: indexPath) as? RadioSwatchItemCollectionViewCell else {
|
||||
fatalError()
|
||||
@ -135,6 +130,11 @@ extension RadioSwatches: UICollectionViewDataSource {
|
||||
}
|
||||
|
||||
extension RadioSwatches: UICollectionViewDelegate {
|
||||
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||
guard let molecule = swatches?[indexPath.row] else {return true }
|
||||
return molecule.enabled ?? true
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioSwatchItemCollectionViewCell else { return }
|
||||
cell.radioSwatch.selectSwatch()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user