Digital ACT191 defect - Carousel indicator disappearing fix.

This commit is contained in:
Scott Pfeil 2024-05-03 12:54:17 -04:00
parent a0168d6e38
commit 6f92282a1d
2 changed files with 22 additions and 15 deletions

View File

@ -26,7 +26,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
/// Sets the current Index to focus on.
public var currentIndex: Int = 0
public var animated: Bool = true
public var hidesForSinglePage: Bool = false
public var hidesForSinglePage: Bool = true
public var inverted: Bool = false
/// Set true to make the accessibility value as "Slide #currentPage of #totalPage", otherwise will be "Page #currentPage of #totalPage", default is false
public var accessibilityHasSlidesInsteadOfPage: Bool = false

View File

@ -69,7 +69,7 @@ open class Carousel: View {
public var delegateObject: MVMCoreUIDelegateObject?
private var size: CGFloat?
// Updates the model and index.
public func updateModelIndex() {
(model as? CarouselModel)?.index = pageIndex
@ -90,12 +90,29 @@ 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,
(model.paging == true || loop == true) else { return }
guard let model = model as? CarouselModel, !model.molecules.isEmpty else { return }
guard (model.paging == true || loop == true) else {
DispatchQueue.main.async { [self] in
updatePagerVisibility()
}
return
}
DispatchQueue.main.async { [self] in
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: false)
collectionView.layoutIfNeeded()
showPeaking(true)
updatePagerVisibility()
}
}
/// Updates if the pager is visible or not.
private func updatePagerVisibility() {
guard let pagingView = pagingView else { return }
let shouldHidePager = collectionView.contentSize.width < bounds.width
if (shouldHidePager && !pagingView.isHidden) || (!shouldHidePager && pagingView.isHidden) {
pagingView.isHidden = shouldHidePager
pagingBottomPin?.isActive = !shouldHidePager
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
}
@ -140,16 +157,6 @@ open class Carousel: View {
(cell as? MVMCoreViewProtocol)?.updateView(size)
}
layoutCollection()
// Check must be dispatched to main for the layout to complete in layoutCollection.
DispatchQueue.main.async { [self] in
let shouldHidePager = molecules?.count ?? 0 < 2 || collectionView.contentSize.width < bounds.width
if let pagingView = pagingView, shouldHidePager != pagingView.isHidden {
pagingView.isHidden = shouldHidePager
pagingBottomPin?.isActive = !shouldHidePager
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
}
}
//--------------------------------------------------
@ -244,7 +251,7 @@ open class Carousel: View {
var pagingView: (MoleculeViewProtocol & CarouselPageControlProtocol)? = nil
if let molecule = molecule,
(!molecule.hidesForSinglePage || numberOfPages > 1) {
(numberOfPages > 1 || molecule.hidesForSinglePage) {
pagingView = ModelRegistry.createMolecule(molecule, delegateObject: delegateObject) as? (MoleculeViewProtocol & CarouselPageControlProtocol)
pagingMoleculeName = molecule.moleculeName
} else {