From 176944f2a0fe56fa08dabe8075e268d124e8465a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 3 Sep 2020 12:13:53 -0400 Subject: [PATCH] height and loop fix --- MVMCoreUI/Atomic/Organisms/Carousel.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel.swift index 6cc67d4e..1abab6e0 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel.swift @@ -50,7 +50,7 @@ open class Carousel: View { /// From 0-1. The item width as a percent of the carousel width. public var itemWidthPercent: CGFloat = 1 - /// The height of the carousel. Default is 300. + /// The height of the carousel. public var collectionViewHeight: NSLayoutConstraint? /// The view that we use for paging @@ -162,6 +162,9 @@ open class Carousel: View { if let height = carouselModel.height { collectionViewHeight?.constant = height + collectionViewHeight?.isActive = true + } else { + collectionViewHeight?.isActive = false } registerCells(with: carouselModel, delegateObject: delegateObject) @@ -492,12 +495,12 @@ extension Carousel: UIScrollViewDelegate { } // If we are swiping to a buffer cell, change to real cell before beginning animation so we don't go out of bounds. - if cellToSwipeTo < 2 { + if loop, cellToSwipeTo < 2 { let newOffset = scrollView.contentOffset.x + (width * CGFloat(numberOfPages)) scrollView.contentOffset.x = newOffset targetContentOffset.pointee.x = newOffset cellToSwipeTo = cellToSwipeTo + numberOfPages - } else if cellToSwipeTo > numberOfPages + 1 { + } else if loop, cellToSwipeTo > numberOfPages + 1 { let newOffset = scrollView.contentOffset.x - (width * CGFloat(numberOfPages)) scrollView.contentOffset.x = newOffset targetContentOffset.pointee.x = newOffset