Code changes after review comment.
This commit is contained in:
parent
6ed16cb35d
commit
1c2cd9ff64
@ -8,17 +8,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc public protocol CarouselItemSelected: class {
|
||||
func itemSelected(fieldValue: String?, index: Int)
|
||||
}
|
||||
|
||||
open class CarouselItem: MoleculeCollectionViewCell, CarouselItemProtocol {
|
||||
|
||||
open var allowsPeaking = false
|
||||
var peakingLeftArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingRightArrow = UIImageView(image: MVMCoreUIUtility.imageNamed("peakingRightArrow")?.withRenderingMode(.alwaysTemplate))
|
||||
var peakingCover = MVMCoreUICommonViewsUtility.commonView()
|
||||
@objc public weak var carouselDelegate: CarouselItemSelected?
|
||||
|
||||
open override func addMolecule(_ molecule: MoleculeViewProtocol) {
|
||||
super.addMolecule(molecule)
|
||||
|
||||
@ -386,7 +386,6 @@ extension Carousel: UICollectionViewDataSource {
|
||||
protocolCell.set(with: moleculeInfo.molecule, delegateObject, nil)
|
||||
}
|
||||
(cell as? MVMCoreViewProtocol)?.updateView(size ?? collectionView.bounds.width)
|
||||
(cell as? CarouselItem)?.carouselDelegate = self
|
||||
setAccessiblity(cell, index: indexPath.row)
|
||||
return cell
|
||||
}
|
||||
@ -394,7 +393,15 @@ extension Carousel: UICollectionViewDataSource {
|
||||
|
||||
extension Carousel: UICollectionViewDelegate {
|
||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
(collectionView.cellForItem(at: indexPath) as? CollectionTemplateItemProtocol)?.didSelectCell(at: indexPath, delegateObject: delegateObject, additionalData: nil)
|
||||
guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionTemplateItemProtocol else {
|
||||
return
|
||||
}
|
||||
cell.didSelectCell(at: indexPath, delegateObject: delegateObject, additionalData: nil)
|
||||
//Check for selectable carousel item
|
||||
guard let carouselModel = model as? CarouselModel, let selectedCarouselItem = carouselModel.molecules[indexPath.row] as? CarouselItemModel, cell.shouldSelect(at: indexPath, delegateObject: delegateObject, additionalData: nil) else {
|
||||
return
|
||||
}
|
||||
carouselModel.selectedIndex = selectedCarouselItem.fieldValue ?? String(indexPath.row)
|
||||
}
|
||||
}
|
||||
|
||||
@ -626,13 +633,3 @@ class CarouselAccessibilityElement: UIAccessibilityElement {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
extension Carousel: CarouselItemSelected {
|
||||
public func itemSelected(fieldValue: String?, index: Int) {
|
||||
if fieldValue != nil {
|
||||
(model as? CarouselModel)?.selectedIndex = fieldValue
|
||||
} else {
|
||||
(model as? CarouselModel)?.selectedIndex = String(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,10 @@ public protocol CollectionTemplateItemProtocol: UICollectionViewCell {
|
||||
|
||||
/// Called when the cell will display.
|
||||
func willDisplay()
|
||||
|
||||
/// Handle the selection of cell
|
||||
func shouldSelect(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Bool
|
||||
|
||||
}
|
||||
|
||||
// Default implementation does nothing
|
||||
@ -26,4 +30,9 @@ extension CollectionTemplateItemProtocol {
|
||||
public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {}
|
||||
|
||||
public func willDisplay() {}
|
||||
|
||||
public func shouldSelect(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -132,4 +132,9 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
||||
autoLayoutAttributes.frame = newFrame
|
||||
return autoLayoutAttributes
|
||||
}
|
||||
|
||||
// Set default to false
|
||||
open func shouldSelect(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) -> Bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user