diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index da762dbb..ff3452fb 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -39,7 +39,7 @@ open class RadioBox: Control { super.setupView() layer.delegate = self - layer.borderColor = UIColor.black.cgColor + layer.borderColor = UIColor.mvmCoolGray6.cgColor layer.borderWidth = 1 label.numberOfLines = 1 @@ -77,11 +77,12 @@ open class RadioBox: Control { // Draw the strikethrough strikeLayer?.removeFromSuperlayer() if isOutOfStock { - let line = getStrikeThrough(color: .black, thickness: 1) + let line = getStrikeThrough(color: isSelected ? .black : .mvmCoolGray6, thickness: 1) layer.addSublayer(line) strikeLayer = line } + // Draw the border borderLayer?.removeFromSuperlayer() if isSelected { @@ -98,6 +99,7 @@ open class RadioBox: Control { if !isEnabled { let mask = getMaskLayer() layer.mask = mask + maskLayer = mask } } @@ -108,6 +110,7 @@ open class RadioBox: Control { } @objc open func selectBox() { + guard isEnabled else { return } isSelected = true radioBoxModel?.selected = isSelected layer.setNeedsDisplay() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index 6fe66bc2..4b42e9a8 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -15,6 +15,7 @@ open class RadioBoxes: View { private let boxWidth: CGFloat = 151.0 private let boxHeight: CGFloat = 64.0 private let itemSpacing: CGFloat = 8.0 + private var numberOfColumns: CGFloat = 2.0 private var delegateObject: MVMCoreUIDelegateObject? @@ -94,7 +95,7 @@ open class RadioBoxes: View { } // Calculate the height - let rows = ceil(CGFloat(boxes.count) / 2.0) + let rows = ceil(CGFloat(boxes.count) / numberOfColumns) let height = (rows * boxHeight) + ((rows - 1) * itemSpacing) collectionViewHeight?.constant = height } @@ -102,7 +103,7 @@ open class RadioBoxes: View { extension RadioBoxes: UICollectionViewDelegateFlowLayout { open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let itemWidth: CGFloat = (collectionView.bounds.width - itemSpacing) / 2 + let itemWidth: CGFloat = (collectionView.bounds.width - itemSpacing) / numberOfColumns return CGSize(width: itemWidth, height: boxHeight) } } @@ -129,6 +130,11 @@ extension RadioBoxes: UICollectionViewDataSource { } extension RadioBoxes: UICollectionViewDelegate { + public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { + guard let molecule = boxes?[indexPath.row] else { return false } + return molecule.enabled + } + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return } cell.radioBox.selectBox()