From 9b048ccd5a0045075136906741bf3009a141d2f4 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 19 May 2023 14:33:47 -0400 Subject: [PATCH] Testing json override. Prospect images tabs and carousel fixes new json --- .../HorizontalCombinationViews/Tabs.swift | 29 +++++++++++++++---- .../Molecules/Items/TabsTableViewCell.swift | 1 + .../Atomic/Organisms/Carousel/Carousel.swift | 4 ++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index de9ef49f..be01746d 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -51,7 +51,7 @@ import VDSColorTokens public let selectionLineMovingTime: TimeInterval = 0.2 //------------------------------------------------- - // MARK:- Layout Views + // MARK: - Layout Views //------------------------------------------------- open override func reset() { @@ -122,8 +122,27 @@ import VDSColorTokens NSLayoutConstraint.constraintPinSubview(bottomLine, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true) } + open override func layoutSubviews() { + super.layoutSubviews() + // Accounts for any collection size changes + DispatchQueue.main.async { + self.layoutCollection() + } + } + + /// Invalidates the layout and ensures we are paged to the correct cell. + open func layoutCollection() { + collectionView?.collectionViewLayout.invalidateLayout() + + // 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. + DispatchQueue.main.async { + self.collectionView?.scrollToItem(at: IndexPath(row: self.selectedIndex, section: 0), at: .left, animated: false) + self.collectionView?.layoutIfNeeded() + } + } + //------------------------------------------------- - // MARK:- Control Methods + // MARK: - Control Methods //------------------------------------------------- public func selectIndex(_ index: Int, animated: Bool) { @@ -146,7 +165,7 @@ import VDSColorTokens } //------------------------------------------------- - // MARK:- Molecule Setup + // MARK: - Molecule Setup //------------------------------------------------- override open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { @@ -163,7 +182,7 @@ import VDSColorTokens } //------------------------------------------------- -// MARK:- Collection View Methods +// MARK: - Collection View Methods //------------------------------------------------- extension Tabs: UICollectionViewDataSource { @@ -281,7 +300,7 @@ extension Tabs: UIScrollViewDelegate { //------------------------------------------------- -// MARK:- Bottom Line Methods +// MARK: - Bottom Line Methods //------------------------------------------------- extension Tabs { func moveSelectionLine(toIndex indexPath: IndexPath, animated: Bool, cell: TabItemCell) { diff --git a/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift index 6a941881..e904707e 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift @@ -47,6 +47,7 @@ import UIKit public override func reset() { super.reset() tabs.reset() + tabs.paddingBeforeFirstTab = false } public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 46 } diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index fcaa1010..4360c2c7 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -104,6 +104,7 @@ open class Carousel: View { super.setupView() collectionView.dataSource = self collectionView.delegate = self + collectionView.bounces = false addSubview(collectionView) bottomPin = NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)?[ConstraintBot] as? NSLayoutConstraint collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) @@ -129,7 +130,8 @@ open class Carousel: View { inset.left = carouselModel?.leftPadding ?? Padding.Component.horizontalPaddingForSize(size) inset.right = carouselModel?.rightPadding ?? Padding.Component.horizontalPaddingForSize(size) } - (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.sectionInset = inset + collectionView.contentInset = inset + //(collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.sectionInset = inset // Update cells and re-layout. for cell in collectionView.visibleCells {