From 750e50d476bfeb68603caf611ad60376577d83ea Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Wed, 12 Jun 2024 15:59:43 -0400 Subject: [PATCH] Digital PCT265 story DE307-731: Support 'gone' configuration for carousel cells. --- MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift | 5 +++++ MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift | 4 ++-- MVMCoreUI/Atomic/Organisms/Carousel/CarouselModel.swift | 4 ++++ .../Protocols/ModelProtocols/CarouselItemModelProtocol.swift | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift b/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift index f7b875c1..bbcca3f6 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift @@ -24,6 +24,7 @@ public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName public var baseValue: AnyHashable? + public var gone: Bool = false //-------------------------------------------------- // MARK: - Validation @@ -53,6 +54,7 @@ case groupName case enabled case readOnly + case gone } //-------------------------------------------------- @@ -76,6 +78,7 @@ if let readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) { self.readOnly = readOnly } + gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) ?? false try super.init(from: decoder) } @@ -99,6 +102,7 @@ && fieldValue == model.fieldValue && enabled == model.enabled && readOnly == model.readOnly + && gone == model.gone } public override func isVisuallyEquivalent(to model: any MoleculeModelComparisonProtocol) -> Bool { @@ -107,5 +111,6 @@ && peakingArrowColor == model.peakingArrowColor && enabled == model.enabled && readOnly == model.readOnly + && gone == model.gone } } diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 12399292..1601acfe 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -90,7 +90,7 @@ open class Carousel: View { showPeaking(false) // Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled. - guard let model = model as? CarouselModel, !model.molecules.isEmpty else { return } + guard let model = model as? CarouselModel, !model.visibleMolecules.isEmpty else { return } guard (model.paging == true || loop == true) else { DispatchQueue.main.async { [self] in updatePagerVisibility() @@ -228,7 +228,7 @@ open class Carousel: View { //-------------------------------------------------- func prepareMolecules(with carouselModel: CarouselModel?) { - guard let newMolecules = carouselModel?.molecules else { + guard let newMolecules = carouselModel?.visibleMolecules else { numberOfPages = 0 molecules = nil return diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/CarouselModel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/CarouselModel.swift index 42c8363c..58ee28e6 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/CarouselModel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/CarouselModel.swift @@ -44,6 +44,10 @@ import UIKit public var selectable = false public var selectedIndex: Int? + public var visibleMolecules: [MoleculeModelProtocol & CarouselItemModelProtocol] { + molecules.filter { !$0.gone } + } + public init(molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]) { self.molecules = molecules } diff --git a/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift b/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift index ed09d90e..affa294b 100644 --- a/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift @@ -9,6 +9,7 @@ public protocol CarouselItemModelProtocol: FormFieldProtocol, ContainerModelProtocol { var analyticsData: JSONValueDictionary? { get set } + var gone: Bool { get set } } public extension CarouselItemModelProtocol {