Merge branch 'feature/carousel_fixes' into 'develop'

Feature/carousel fixes

See merge request BPHV_MIPS/mvm_core_ui!301
This commit is contained in:
Pfeil, Scott Robert 2020-03-13 11:41:34 -04:00
commit 5429cdc70f

View File

@ -10,13 +10,13 @@ import UIKit
open class Carousel: View {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
public let collectionView = UICollectionView(frame: .zero, 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.
var pageIndex: Int {
public var pageIndex: Int {
get {
return loop ? currentIndex - 2 : currentIndex
}
@ -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,20 +35,20 @@ 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)?
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() {
@ -230,7 +230,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,22 +252,22 @@ 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)
}
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)
}
}
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()
@ -336,7 +336,7 @@ 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)