Digital PCT265 defect CXTDT-579050: Carousel cell registration check.

This commit is contained in:
Hedden, Kyle Matthew 2024-07-03 18:40:43 -04:00
parent 90f9a0bcf5
commit b2ad684f00

View File

@ -43,6 +43,9 @@ open class Carousel: View {
/// The models for the molecules. /// The models for the molecules.
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]? public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]?
/// A list of currently registered cells.
public var registeredMoleculeIds: [String]?
/// The horizontal alignment of the cell in the collection view. Only noticeable if the itemWidthPercent is less than 100%. /// The horizontal alignment of the cell in the collection view. Only noticeable if the itemWidthPercent is less than 100%.
public var itemAlignment = UICollectionView.ScrollPosition.left public var itemAlignment = UICollectionView.ScrollPosition.left
@ -174,9 +177,7 @@ open class Carousel: View {
MVMCoreLoggingHandler.shared()?.handleDebugMessage("[\(Self.self)] [\(ObjectIdentifier(self).hashValue)]\noriginal model: \(originalModel?.debugDescription ?? "none")\nnew model: \(model)") MVMCoreLoggingHandler.shared()?.handleDebugMessage("[\(Self.self)] [\(ObjectIdentifier(self).hashValue)]\noriginal model: \(originalModel?.debugDescription ?? "none")\nnew model: \(model)")
if #available(iOS 15.0, *) { if #available(iOS 15.0, *) {
if let originalModel, carouselModel.isDeeplyVisuallyEquivalent(to: originalModel), if hasSameCellRegistration(with: carouselModel, delegateObject: delegateObject) {
originalModel.visibleMolecules.isVisuallyEquivalent(to: molecules ?? []) // Since the carousel model's children are in place replaced and we do not have a deep copy of this model tree, add in this hack to check if the prior captured carousel items match the newly visible ones.
{
// Prevents a carousel reset while still updating the cell backing data through reconfigureItems. // Prevents a carousel reset while still updating the cell backing data through reconfigureItems.
MVMCoreLoggingHandler.shared()?.handleDebugMessage("[\(Self.self)] Model is visually equivalent. Skipping rebuild...") MVMCoreLoggingHandler.shared()?.handleDebugMessage("[\(Self.self)] Model is visually equivalent. Skipping rebuild...")
prepareMolecules(with: carouselModel) prepareMolecules(with: carouselModel)
@ -284,23 +285,27 @@ open class Carousel: View {
/// Registers the cells with the collection view /// Registers the cells with the collection view
func registerCells(with carouselModel: CarouselModel, delegateObject: MVMCoreUIDelegateObject?) { func registerCells(with carouselModel: CarouselModel, delegateObject: MVMCoreUIDelegateObject?) {
var registeredIds = [String]()
for molecule in carouselModel.molecules { for molecule in carouselModel.molecules {
if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) { if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) {
collectionView.register(info.class, forCellWithReuseIdentifier: info.identifier) collectionView.register(info.class, forCellWithReuseIdentifier: info.identifier)
registeredIds.append(info.identifier)
} else {
registeredIds.append(molecule.moleculeName)
} }
} }
let moleculeInfo = carouselModel.molecules.map { registeredMoleculeIds = registeredIds
getMoleculeInfo(with: $0, delegateObject: delegateObject) }
}
// For each molecule with info, register it. func hasSameCellRegistration(with carouselModel: CarouselModel, delegateObject: MVMCoreUIDelegateObject?) -> Bool {
moleculeInfo.compactMap({ $0 }).forEach { collectionView.register($0.class, forCellWithReuseIdentifier: $0.identifier) } let incomingIds = carouselModel.molecules.map { molecule in
for molecule in carouselModel.molecules {
if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) { if let info = getMoleculeInfo(with: molecule, delegateObject: delegateObject) {
collectionView.register(info.class, forCellWithReuseIdentifier: info.identifier) return info.identifier
} else {
return molecule.moleculeName
} }
} }
return incomingIds == registeredMoleculeIds
} }
//-------------------------------------------------- //--------------------------------------------------