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