From 7441968f41070ad6a4c31c2553d9bcb541edaaee Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Thu, 8 Jul 2021 01:50:49 +0530 Subject: [PATCH] pagination, model and reset fixes --- .../Views/CarouselIndicator/BarsIndicatorView.swift | 1 + .../Views/CarouselIndicator/CarouselIndicator.swift | 6 ++++++ MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 975c7ebb..8a1f960b 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -234,6 +234,7 @@ open class BarsIndicatorView: CarouselIndicator { super.reset() barReferences.forEach { $0.removeFromSuperview() } barReferences = [] + currentIndex = 0 } public override func updateUI(previousIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) { diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index 6a82ef80..5b04d065 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -248,4 +248,10 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { bottomConstraint?.constant = constant topConstraint?.constant = constant } + + open override func reset() { + super.reset() + currentIndex = 0 + previousIndex = 0 + } } diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 1762b9ce..151574c7 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -177,6 +177,7 @@ open class Carousel: View { if let selectedIndex = carouselModel.selectedIndex { let adjustedIndex = loop ? selectedIndex + 2 : selectedIndex collectionView.selectItem(at: IndexPath(row: adjustedIndex, section: 0), animated: false, scrollPosition: []) + goTo(adjustedIndex, animated: false) } } @@ -207,6 +208,13 @@ open class Carousel: View { pageIndex = 0 } + open override func reset() { + super.reset() + currentIndex = 0 + pageIndex = 0 + pagingView?.reset() + } + var pagingMoleculeName: String? /// Sets up the paging molecule @@ -425,6 +433,10 @@ extension Carousel: UICollectionViewDelegate { adjustedIndex = adjustedIndex + numberOfPages } model.selectedIndex = adjustedIndex + currentIndex = adjustedIndex + pageIndex = currentIndex + pagingView?.currentIndex = adjustedIndex + updateModelIndex() } if let cell = collectionView.cellForItem(at: indexPath) as? CollectionTemplateItemProtocol { cell.didSelectCell(at: indexPath, delegateObject: delegateObject, additionalData: nil)