final carousel fixes

This commit is contained in:
Khan, Arshad 2021-07-09 03:04:16 +05:30
parent 7441968f41
commit b1ff5b2a64
2 changed files with 9 additions and 3 deletions

View File

@ -41,7 +41,7 @@ open class Carousel: View {
open var numberOfPages = 0
/// The models for the molecules.
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]?
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol & CollectionItemModelProtocol]?
/// The horizontal alignment of the cell in the collection view. Only noticeable if the itemWidthPercent is less than 100%.
public var itemAlignment = UICollectionView.ScrollPosition.left
@ -79,6 +79,7 @@ open class Carousel: View {
DispatchQueue.main.async {
self.layoutCollection()
}
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
/// Invalidates the layout and ensures we are paged to the correct cell.
@ -398,6 +399,11 @@ extension Carousel: UICollectionViewDelegateFlowLayout {
}
extension Carousel: UICollectionViewDataSource {
open func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return molecules?.count ?? 0
}

View File

@ -20,7 +20,7 @@ import UIKit
}
public var backgroundColor: Color?
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol & CollectionItemModelProtocol]
public var index: Int = 0
public var spacing: CGFloat?
public var border: Bool?
@ -41,7 +41,7 @@ import UIKit
public var selectable = false
public var selectedIndex: Int?
public init(molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]) {
public init(molecules: [MoleculeModelProtocol & CarouselItemModelProtocol & CollectionItemModelProtocol]) {
self.molecules = molecules
}