From 3970b34719cb4b082446cfd9f86684586a00df34 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Tue, 10 Mar 2020 01:15:37 +0530 Subject: [PATCH 1/8] Making few properties public. Constraint fixes. --- MVMCoreUI/Organisms/Carousel.swift | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 9e2422e6..f8e2f37f 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -10,7 +10,7 @@ import UIKit open class Carousel: View { - let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + public let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: MVMCoreUISplitViewController.getDetailViewWidth(), height: 300), collectionViewLayout: UICollectionViewFlowLayout()) /// The current index of the collection view. Includes dummy cells when looping. var currentIndex = 0 @@ -26,7 +26,7 @@ open class Carousel: View { } /// The number of pages that there are. Used for the page control and for calculations. Should not include the looping dummy cells. Be sure to set this if subclassing and not using the molecules. - var numberOfPages = 0 + open var numberOfPages = 0 /// The json for the molecules. var molecules: [MoleculeModelProtocol]? @@ -35,10 +35,10 @@ open class Carousel: View { var itemAlignment = UICollectionView.ScrollPosition.left /// From 0-1. The item width as a percent of the carousel width. - var itemWidthPercent: Float = 1 + public var itemWidthPercent: Float = 1 /// The height of the carousel. Default is 300. - var collectionViewHeight: NSLayoutConstraint? + public var collectionViewHeight: NSLayoutConstraint? /// The view that we use for paging var pagingView: (UIView & MVMCoreUIPagingProtocol)? @@ -65,7 +65,7 @@ open class Carousel: View { addSubview(collectionView) bottomPin = NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)?[ConstraintBot] as? NSLayoutConstraint - collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) + collectionViewHeight = collectionView.heightAnchor.constraint(greaterThanOrEqualToConstant: 300) collectionViewHeight?.isActive = false } @@ -114,6 +114,7 @@ open class Carousel: View { layout.scrollDirection = .horizontal layout.minimumLineSpacing = CGFloat(carouselModel?.spacing ?? 1) layout.minimumInteritemSpacing = 0 + layout.itemSize = CGSize(width: MVMCoreUISplitViewController.getDetailViewWidth(), height: 300) collectionView.collectionViewLayout = layout } @@ -190,12 +191,12 @@ open class Carousel: View { pagingView.translatesAutoresizingMaskIntoConstraints = false addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true - collectionView.bottomAnchor.constraint(equalTo: pagingView.centerYAnchor, constant: position).isActive = true + collectionView.bottomAnchor.constraint(equalTo: pagingView.topAnchor, constant: position).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true bottomPin?.isActive = false bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.priority = .defaultLow - bottomPin?.isActive = true + bottomPin?.isActive = false pagingView.setNumberOfPages(numberOfPages) (pagingView as? MVMCoreUIViewConstrainingProtocol)?.alignHorizontal?(.fill) @@ -230,7 +231,7 @@ open class Carousel: View { } } - func setAccessiblity(_ cell: UICollectionViewCell?, index: Int) { + public func setAccessiblity(_ cell: UICollectionViewCell?, index: Int) { guard let cell = cell else { return } @@ -252,7 +253,7 @@ open class Carousel: View { } extension Carousel: UICollectionViewDelegateFlowLayout { - public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let itemWidth = collectionView.bounds.width * CGFloat(itemWidthPercent) return CGSize(width: itemWidth, height: collectionView.bounds.height) } @@ -263,11 +264,11 @@ extension Carousel: UICollectionViewDelegateFlowLayout { } extension Carousel: UICollectionViewDataSource { - public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return molecules?.count ?? 0 } - public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let molecule = molecules?[indexPath.row], let moleculeInfo = getMoleculeInfo(with: molecule, delegateObject: nil) else { return UICollectionViewCell() @@ -343,6 +344,8 @@ extension Carousel: UIScrollViewDelegate { // Let the pager know our progress if needed. pagingView?.scrollViewDidScroll?(collectionView) + + collectionView.collectionViewLayout.invalidateLayout() } public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { From 955d398262e4aa925f1a2ddb4f415eea47ff3bcc Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Tue, 10 Mar 2020 20:11:25 +0530 Subject: [PATCH 2/8] making properties and function public --- MVMCoreUI/Organisms/Carousel.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index f8e2f37f..6fab0f68 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -41,14 +41,14 @@ open class Carousel: View { public var collectionViewHeight: NSLayoutConstraint? /// The view that we use for paging - var pagingView: (UIView & MVMCoreUIPagingProtocol)? + public var pagingView: (UIView & MVMCoreUIPagingProtocol)? /// If the carousel should loop after scrolling past the first and final cells. var loop = false private var dragging = false // For adding pager - private var bottomPin: NSLayoutConstraint? + public var bottomPin: NSLayoutConstraint? // MARK: - MVMCoreViewProtocol open override func setupView() { @@ -258,7 +258,7 @@ extension Carousel: UICollectionViewDelegateFlowLayout { return CGSize(width: itemWidth, height: collectionView.bounds.height) } - public func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { (cell as? MoleculeCollectionViewCell)?.setPeaking(false, animated: false) } } From bd4450a7fc856d439e7af4a78e3af1ee8ec2a830 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Wed, 11 Mar 2020 22:42:08 +0530 Subject: [PATCH 3/8] making pageIndex public --- MVMCoreUI/Organisms/Carousel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 6fab0f68..b9847487 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -16,7 +16,7 @@ open class Carousel: View { var currentIndex = 0 /// The index of the page, does not include dummy cells. - var pageIndex: Int { + public var pageIndex: Int { get { return loop ? currentIndex - 2 : currentIndex } From 73230fa3411d0a4315cc4fdde49b0bf055277a46 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Fri, 13 Mar 2020 01:55:58 +0530 Subject: [PATCH 4/8] implemented feedback --- MVMCoreUI/Organisms/Carousel.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index b9847487..94c47f4b 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -13,7 +13,7 @@ open class Carousel: View { public let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: MVMCoreUISplitViewController.getDetailViewWidth(), height: 300), collectionViewLayout: UICollectionViewFlowLayout()) /// The current index of the collection view. Includes dummy cells when looping. - var currentIndex = 0 + public var currentIndex = 0 /// The index of the page, does not include dummy cells. public var pageIndex: Int { @@ -114,7 +114,6 @@ open class Carousel: View { layout.scrollDirection = .horizontal layout.minimumLineSpacing = CGFloat(carouselModel?.spacing ?? 1) layout.minimumInteritemSpacing = 0 - layout.itemSize = CGSize(width: MVMCoreUISplitViewController.getDetailViewWidth(), height: 300) collectionView.collectionViewLayout = layout } @@ -184,19 +183,19 @@ open class Carousel: View { pagingView?.removeFromSuperview() guard let pagingView = view else { bottomPin?.isActive = false - bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) + bottomPin = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.isActive = true return } pagingView.translatesAutoresizingMaskIntoConstraints = false addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true - collectionView.bottomAnchor.constraint(equalTo: pagingView.topAnchor, constant: position).isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true + collectionView.bottomAnchor.constraint(equalTo: pagingView.bottomAnchor, constant: position).isActive = true + safeAreaLayoutGuide.bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true bottomPin?.isActive = false - bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) + bottomPin = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.priority = .defaultLow - bottomPin?.isActive = false + bottomPin?.isActive = true pagingView.setNumberOfPages(numberOfPages) (pagingView as? MVMCoreUIViewConstrainingProtocol)?.alignHorizontal?(.fill) From 022f76b8b218c230c5d7cb3ce0ad0e9dddd59ea7 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Fri, 13 Mar 2020 19:28:55 +0530 Subject: [PATCH 5/8] Removing hard coded width. --- MVMCoreUI/Organisms/Carousel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 94c47f4b..8ddeca5f 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -10,7 +10,7 @@ import UIKit open class Carousel: View { - public let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: MVMCoreUISplitViewController.getDetailViewWidth(), height: 300), collectionViewLayout: UICollectionViewFlowLayout()) + public let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) /// The current index of the collection view. Includes dummy cells when looping. public var currentIndex = 0 From 9b8046009af7c5efdb0908cc4e2a481024572f89 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Fri, 13 Mar 2020 20:23:20 +0530 Subject: [PATCH 6/8] Removed un-necessary code. --- MVMCoreUI/Organisms/Carousel.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 8ddeca5f..b1cd0f37 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -183,7 +183,7 @@ open class Carousel: View { pagingView?.removeFromSuperview() guard let pagingView = view else { bottomPin?.isActive = false - bottomPin = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) + bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.isActive = true return } @@ -191,9 +191,9 @@ open class Carousel: View { addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true collectionView.bottomAnchor.constraint(equalTo: pagingView.bottomAnchor, constant: position).isActive = true - safeAreaLayoutGuide.bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true bottomPin?.isActive = false - bottomPin = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) + bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.priority = .defaultLow bottomPin?.isActive = true @@ -336,15 +336,13 @@ extension Carousel: UIScrollViewDelegate { handleUserOnBufferCell() } - public func scrollViewDidScroll(_ scrollView: UIScrollView) { + open func scrollViewDidScroll(_ scrollView: UIScrollView) { // Check if the user is dragging the card even further past the next card. checkForDraggingOutOfBounds(scrollView) // Let the pager know our progress if needed. pagingView?.scrollViewDidScroll?(collectionView) - - collectionView.collectionViewLayout.invalidateLayout() } public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { From d99090bc4425f93d592a70358a0667aa88bdd1f2 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Fri, 13 Mar 2020 20:29:02 +0530 Subject: [PATCH 7/8] Reverted back centerYAnchor --- MVMCoreUI/Organisms/Carousel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index b1cd0f37..64284cbd 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -190,7 +190,7 @@ open class Carousel: View { pagingView.translatesAutoresizingMaskIntoConstraints = false addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true - collectionView.bottomAnchor.constraint(equalTo: pagingView.bottomAnchor, constant: position).isActive = true + collectionView.bottomAnchor.constraint(equalTo: pagingView.centerYAnchor, constant: position).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true bottomPin?.isActive = false bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) From 09be34e4f8f218800a5f2d7ac1134f997c2b2824 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Fri, 13 Mar 2020 20:39:36 +0530 Subject: [PATCH 8/8] Reverted collectioViewHeight constraint. --- MVMCoreUI/Organisms/Carousel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index 64284cbd..ba675adf 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -65,7 +65,7 @@ open class Carousel: View { addSubview(collectionView) bottomPin = NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)?[ConstraintBot] as? NSLayoutConstraint - collectionViewHeight = collectionView.heightAnchor.constraint(greaterThanOrEqualToConstant: 300) + collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) collectionViewHeight?.isActive = false }