Merge branch 'bugfix/radiobox_issues' into 'release/7_6_0'

bugfix/radiobox_issues

See merge request BPHV_MIPS/mvm_core_ui!374
This commit is contained in:
Pfeil, Scott Robert 2020-04-15 13:02:23 -04:00
commit 20b6d4d272
2 changed files with 13 additions and 4 deletions

View File

@ -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()

View File

@ -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()