From 2877534c704cb346628c3c04dcca7a9b87ce8b59 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Fri, 8 Mar 2024 16:45:11 -0500 Subject: [PATCH 1/7] Hide and show the carousel pager based upon the content size. --- .../Atomic/Organisms/Carousel/Carousel.swift | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 421c2e95..a9fcc040 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -55,6 +55,9 @@ open class Carousel: View { /// The view that we use for paging public var pagingView: (MoleculeViewProtocol & CarouselPageControlProtocol)? + /// The pagingView anchor to the bottom of the carousel. Disabled when the pagingView is hidden. + public var pagingBottomPin: NSLayoutConstraint? + /// If the carousel should loop after scrolling past the first and final cells. public var loop = false @@ -89,10 +92,16 @@ open class Carousel: View { // 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 } - DispatchQueue.main.async { - self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false) - self.collectionView.layoutIfNeeded() - self.showPeaking(true) + DispatchQueue.main.async { [self] in + collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: false) + collectionView.layoutIfNeeded() + showPeaking(true) + + let shouldHidePager = model.molecules.isEmpty || collectionView.contentSize.width < bounds.width + if let pagingView = pagingView, shouldHidePager != pagingView.isHidden { + pagingView.isHidden = shouldHidePager + pagingBottomPin?.isActive = !shouldHidePager + } } } @@ -276,7 +285,8 @@ open class Carousel: View { addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true collectionView.bottomAnchor.constraint(equalTo: pagingView.centerYAnchor, constant: position).isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true + pagingBottomPin = bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor) + pagingBottomPin?.isActive = true bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.priority = .defaultLow bottomPin?.isActive = true From 73d13ba37b0a51b2eda83b22d186f7f096c999ab Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Fri, 8 Mar 2024 16:53:40 -0500 Subject: [PATCH 2/7] Pager should still hide on the empty condition. --- .../Atomic/Organisms/Carousel/Carousel.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index a9fcc040..0328e1ff 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -96,12 +96,6 @@ open class Carousel: View { collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: false) collectionView.layoutIfNeeded() showPeaking(true) - - let shouldHidePager = model.molecules.isEmpty || collectionView.contentSize.width < bounds.width - if let pagingView = pagingView, shouldHidePager != pagingView.isHidden { - pagingView.isHidden = shouldHidePager - pagingBottomPin?.isActive = !shouldHidePager - } } } @@ -146,6 +140,15 @@ 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?.isEmpty ?? true || collectionView.contentSize.width < bounds.width + if let pagingView = pagingView, shouldHidePager != pagingView.isHidden { + pagingView.isHidden = shouldHidePager + pagingBottomPin?.isActive = !shouldHidePager + } + } } //-------------------------------------------------- From 959bdce13f57b78bf71edce5dfab2462b547a817 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 11 Mar 2024 10:45:55 -0400 Subject: [PATCH 3/7] Code review. Include the only 1 element condition to the carousel pager logic. --- MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 0328e1ff..5dd4612b 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -143,7 +143,7 @@ open class Carousel: View { // Check must be dispatched to main for the layout to complete in layoutCollection. DispatchQueue.main.async { [self] in - let shouldHidePager = molecules?.isEmpty ?? true || collectionView.contentSize.width < bounds.width + let shouldHidePager = molecules?.count ?? 0 < 2 || collectionView.contentSize.width < bounds.width if let pagingView = pagingView, shouldHidePager != pagingView.isHidden { pagingView.isHidden = shouldHidePager pagingBottomPin?.isActive = !shouldHidePager From 19b4fb308c0d3dfa989b77ebe3db4915f30e9693 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 11 Mar 2024 14:11:17 -0400 Subject: [PATCH 4/7] Code review -- Update of molecule layout change when pager is state changes. --- MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 5dd4612b..c4f7d825 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -147,6 +147,7 @@ open class Carousel: View { if let pagingView = pagingView, shouldHidePager != pagingView.isHidden { pagingView.isHidden = shouldHidePager pagingBottomPin?.isActive = !shouldHidePager + delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } } } From bfe209305d489de1b9c1ee40deb44c0211a0df8c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 11 Mar 2024 15:36:40 -0500 Subject: [PATCH 5/7] added heightConstraint for the twobutton Signed-off-by: Matt Bruce --- .../HorizontalCombinationViews/TwoButtonView.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 4785cfb9..34e0bd11 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -17,11 +17,11 @@ import VDS open var viewModel: TwoButtonViewModel! open var delegateObject: MVMCoreUIDelegateObject? open var additionalData: [AnyHashable : Any]? - + open var primaryButton = PillButton() open var secondaryButton = PillButton() private var buttonGroup = VDS.ButtonGroup() - + private var heightConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- @@ -34,6 +34,7 @@ import VDS buttonGroup.alignment = .center buttonGroup.rowQuantityPhone = 2 buttonGroup.rowQuantityTablet = 2 + heightConstraint = height(constant: VDS.Button.Size.large.height, priority: .defaultHigh) } //-------------------------------------------------- @@ -70,6 +71,8 @@ import VDS if buttons.count != buttonGroup.buttons.count { buttonGroup.buttons = buttons } + + heightConstraint?.constant = primaryButton.size == .small || secondaryButton.size == .small ? VDS.Button.Size.small.height : VDS.Button.Size.large.height } //-------------------------------------------------- From 5ba126038367d836c9f875c42c54d1064d3967ef Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 11 Mar 2024 16:44:53 -0500 Subject: [PATCH 6/7] updated to required Signed-off-by: Matt Bruce --- .../Molecules/HorizontalCombinationViews/TwoButtonView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 34e0bd11..536bc16b 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -34,7 +34,7 @@ import VDS buttonGroup.alignment = .center buttonGroup.rowQuantityPhone = 2 buttonGroup.rowQuantityTablet = 2 - heightConstraint = height(constant: VDS.Button.Size.large.height, priority: .defaultHigh) + heightConstraint = height(constant: VDS.Button.Size.large.height, priority: .required) } //-------------------------------------------------- From 8d57b0ae0e50bfb965ca026e1f18d68aa20d262f Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 11 Mar 2024 17:46:13 -0400 Subject: [PATCH 7/7] Remove 2-way binding on Tabs selected index to avoid applying 0 on view reset. --- .../Molecules/HorizontalCombinationViews/Tabs.swift | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index 2d176986..654e48ac 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -41,16 +41,6 @@ import VDS } } } - - //-------------------------------------------------- - // MARK: - Public Properties Overrides - //-------------------------------------------------- - open override var selectedIndex: Int { - didSet { - guard let viewModel else { return } - viewModel.selectedIndex = selectedIndex - } - } //------------------------------------------------- // MARK: - Layout Views