Making few properties public.

Constraint fixes.
This commit is contained in:
Khan, Arshad 2020-03-10 01:15:37 +05:30
parent 50d20704e7
commit 3970b34719

View File

@ -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) {