Carousel form changes
This commit is contained in:
parent
8a7f11988a
commit
88ff5b2b9d
@ -8,12 +8,17 @@
|
||||
|
||||
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)
|
||||
|
||||
@ -21,6 +21,7 @@ import Foundation
|
||||
public var peakingUI: Bool?
|
||||
public var peakingArrowColor: Color?
|
||||
public var analyticsData: JSONValueDictionary?
|
||||
public var fieldValue: String?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
@ -30,6 +31,7 @@ import Foundation
|
||||
case peakingUI
|
||||
case peakingArrowColor
|
||||
case analyticsData
|
||||
case fieldValue
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -41,6 +43,7 @@ import Foundation
|
||||
peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI)
|
||||
peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor)
|
||||
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
|
||||
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
||||
try super.init(from: decoder)
|
||||
}
|
||||
|
||||
@ -50,5 +53,6 @@ import Foundation
|
||||
try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
|
||||
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)
|
||||
try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
|
||||
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,6 +167,7 @@ open class Carousel: View {
|
||||
|
||||
registerCells(with: carouselModel, delegateObject: delegateObject)
|
||||
prepareMolecules(with: carouselModel)
|
||||
FormValidator.setupValidation(for: carouselModel, delegate: delegateObject?.formHolderDelegate)
|
||||
|
||||
setupPagingMolecule(carouselModel.pagingMolecule, delegateObject: delegateObject)
|
||||
|
||||
@ -385,6 +386,7 @@ 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
|
||||
}
|
||||
@ -624,3 +626,13 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
import UIKit
|
||||
|
||||
|
||||
@objcMembers public class CarouselModel: MoleculeModelProtocol {
|
||||
@objcMembers public class CarouselModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -33,11 +34,30 @@ import UIKit
|
||||
public var leftPadding: CGFloat?
|
||||
public var rightPadding: CGFloat?
|
||||
public var accessibilityText: String?
|
||||
|
||||
public var selectedIndex: String?
|
||||
public var baseValue: AnyHashable?
|
||||
public var fieldKey: String?
|
||||
public var groupName: String = FormValidator.defaultGroupName
|
||||
|
||||
public init(molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]) {
|
||||
self.molecules = molecules
|
||||
}
|
||||
|
||||
public func formFieldValue() -> AnyHashable? {
|
||||
var carouselItemFieldValue: AnyHashable?
|
||||
guard let visibleCarouselItem = molecules[index] as? CarouselItemModel else {
|
||||
return nil
|
||||
}
|
||||
if selectedIndex != nil {
|
||||
//For selectableCarouselItem
|
||||
carouselItemFieldValue = selectedIndex
|
||||
} else {
|
||||
//For carouselItem
|
||||
carouselItemFieldValue = (visibleCarouselItem.fieldValue != nil) ? visibleCarouselItem.fieldValue : String(index)
|
||||
}
|
||||
return carouselItemFieldValue
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
@ -59,6 +79,8 @@ import UIKit
|
||||
case leftPadding
|
||||
case rightPadding
|
||||
case accessibilityText
|
||||
case groupName
|
||||
case fieldKey
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -86,6 +108,11 @@ import UIKit
|
||||
leftPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .leftPadding)
|
||||
rightPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .rightPadding)
|
||||
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||
self.groupName = groupName
|
||||
}
|
||||
baseValue = formFieldValue()
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -105,5 +132,7 @@ import UIKit
|
||||
try container.encodeIfPresent(leftPadding, forKey: .leftPadding)
|
||||
try container.encodeIfPresent(rightPadding, forKey: .rightPadding)
|
||||
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
|
||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||
try container.encode(groupName, forKey: .groupName)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user