Commit 2aa73721 by Daniel Dahan

samples issue-99: Fixed layout issues in CollectionView, where the sizing was…

samples issue-99: Fixed layout issues in CollectionView, where the sizing was not correctlly being initialized.
parent 6612bfd0
## 2.12.18
* Fixed layout issues in CollectionView, where the sizing was not correctlly being initialized.
## 2.12.17
* [pr-979](https://github.com/CosmicMind/Material/pull/979): Added `visibilityOff` icon and updated `TextField` to utilize it.
......
......@@ -114,16 +114,14 @@ open class CollectionView: UICollectionView {
- Parameter frame: A CGRect defining the view's frame.
*/
public init(frame: CGRect) {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 100, height: 100)
super.init(frame: frame, collectionViewLayout: layout)
let layout = CollectionViewLayout()
super.init(frame: frame, collectionViewLayout: layout)
prepare()
}
/// A convenience initializer that initializes the object.
public init() {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 100, height: 100)
let layout = CollectionViewLayout()
super.init(frame: .zero, collectionViewLayout: layout)
prepare()
}
......
......@@ -99,7 +99,7 @@ extension CollectionViewController {
fileprivate func prepareCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
view.addSubview(collectionView)
view.layout(collectionView).edges()
}
}
......
......@@ -149,7 +149,7 @@ extension CollectionViewLayout {
open override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
let dataSourceItem = dataSourceItems![indexPath.item]
if 0 < itemSize.width && 0 < itemSize.height {
attributes.frame = CGRect(x: offset.x, y: offset.y, width: itemSize.width - contentEdgeInsets.left - contentEdgeInsets.right, height: itemSize.height - contentEdgeInsets.top - contentEdgeInsets.bottom)
} else if .vertical == scrollDirection {
......@@ -157,6 +157,7 @@ extension CollectionViewLayout {
attributes.frame = CGRect(x: contentEdgeInsets.left, y: offset.y, width: collectionView!.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right, height: h)
} else if let v = dataSourceItem.data as? UIView, 0 < v.bounds.height {
v.updateConstraintsIfNeeded()
v.updateConstraints()
v.setNeedsLayout()
v.layoutIfNeeded()
......@@ -171,6 +172,7 @@ extension CollectionViewLayout {
attributes.frame = CGRect(x: offset.x, y: contentEdgeInsets.top, width: w, height: collectionView!.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom)
} else if let v = dataSourceItem.data as? UIView, 0 < v.bounds.width {
v.updateConstraintsIfNeeded()
v.updateConstraints()
v.setNeedsLayout()
v.layoutIfNeeded()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment