Merge branch 'bugfix/carousel_indicator_missing' into 'develop'
Digital ACT191 defect - Carousel indicator disappearing fix. ### Summary Missing carousel indicator. Co-authored-by: Scott Pfeil <Scott.Pfeil3@verizonwireless.com> See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1109
This commit is contained in:
commit
4cd43dcfbe
@ -26,7 +26,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
|
|||||||
/// Sets the current Index to focus on.
|
/// Sets the current Index to focus on.
|
||||||
public var currentIndex: Int = 0
|
public var currentIndex: Int = 0
|
||||||
public var animated: Bool = true
|
public var animated: Bool = true
|
||||||
public var hidesForSinglePage: Bool = false
|
public var hidesForSinglePage: Bool = true
|
||||||
public var inverted: Bool = false
|
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
|
/// 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
|
public var accessibilityHasSlidesInsteadOfPage: Bool = false
|
||||||
|
|||||||
@ -69,7 +69,7 @@ open class Carousel: View {
|
|||||||
public var delegateObject: MVMCoreUIDelegateObject?
|
public var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
|
||||||
private var size: CGFloat?
|
private var size: CGFloat?
|
||||||
|
|
||||||
// Updates the model and index.
|
// Updates the model and index.
|
||||||
public func updateModelIndex() {
|
public func updateModelIndex() {
|
||||||
(model as? CarouselModel)?.index = pageIndex
|
(model as? CarouselModel)?.index = pageIndex
|
||||||
@ -90,12 +90,29 @@ open class Carousel: View {
|
|||||||
showPeaking(false)
|
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.
|
// 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,
|
guard let model = model as? CarouselModel, !model.molecules.isEmpty else { return }
|
||||||
(model.paging == true || loop == true) else { return }
|
guard (model.paging == true || loop == true) else {
|
||||||
|
DispatchQueue.main.async { [self] in
|
||||||
|
updatePagerVisibility()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
DispatchQueue.main.async { [self] in
|
DispatchQueue.main.async { [self] in
|
||||||
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: false)
|
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: false)
|
||||||
collectionView.layoutIfNeeded()
|
collectionView.layoutIfNeeded()
|
||||||
showPeaking(true)
|
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)
|
(cell as? MVMCoreViewProtocol)?.updateView(size)
|
||||||
}
|
}
|
||||||
layoutCollection()
|
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
|
var pagingView: (MoleculeViewProtocol & CarouselPageControlProtocol)? = nil
|
||||||
if let molecule = molecule,
|
if let molecule = molecule,
|
||||||
(!molecule.hidesForSinglePage || numberOfPages > 1) {
|
(numberOfPages > 1 || !molecule.hidesForSinglePage) {
|
||||||
pagingView = ModelRegistry.createMolecule(molecule, delegateObject: delegateObject) as? (MoleculeViewProtocol & CarouselPageControlProtocol)
|
pagingView = ModelRegistry.createMolecule(molecule, delegateObject: delegateObject) as? (MoleculeViewProtocol & CarouselPageControlProtocol)
|
||||||
pagingMoleculeName = molecule.moleculeName
|
pagingMoleculeName = molecule.moleculeName
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user