Moving flow layout to a new class
This commit is contained in:
parent
d94c845eb3
commit
e1589577fe
@ -27,6 +27,7 @@
|
||||
44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; };
|
||||
44A952D92BE384C40009F874 /* TableCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952D82BE384C40009F874 /* TableCellModel.swift */; };
|
||||
44A952DB2BE3852E0009F874 /* TableCellLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */; };
|
||||
44A952DD2BE3DA820009F874 /* TableFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */; };
|
||||
5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; };
|
||||
5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; };
|
||||
710607952B91A99500F2863F /* TitleletChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 710607942B91A99500F2863F /* TitleletChangeLog.txt */; };
|
||||
@ -220,6 +221,7 @@
|
||||
44604AD629CE196600E62B51 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
|
||||
44A952D82BE384C40009F874 /* TableCellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableCellModel.swift; sourceTree = "<group>"; };
|
||||
44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableCellLabelModel.swift; sourceTree = "<group>"; };
|
||||
44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableFlowLayout.swift; sourceTree = "<group>"; };
|
||||
5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Useable.swift; sourceTree = "<group>"; };
|
||||
5FC35BE228D51405004EBEAC /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
|
||||
710607942B91A99500F2863F /* TitleletChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TitleletChangeLog.txt; sourceTree = "<group>"; };
|
||||
@ -440,6 +442,7 @@
|
||||
children = (
|
||||
440B84C92BD8E0E9004A732A /* Table.swift */,
|
||||
443DBAF92BDA303F0021497E /* TableCellItem.swift */,
|
||||
44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */,
|
||||
44A952D82BE384C40009F874 /* TableCellModel.swift */,
|
||||
44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */,
|
||||
);
|
||||
@ -1226,6 +1229,7 @@
|
||||
EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */,
|
||||
EA5E30532950DDA60082B959 /* TitleLockup.swift in Sources */,
|
||||
EAD062B02A3B873E0015965D /* BadgeIndicator.swift in Sources */,
|
||||
44A952DD2BE3DA820009F874 /* TableFlowLayout.swift in Sources */,
|
||||
EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */,
|
||||
18792A902B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift in Sources */,
|
||||
EA0B18062A9E2D2D00F2D0CD /* SelectorItemBase.swift in Sources */,
|
||||
|
||||
@ -124,25 +124,3 @@ extension Table: UICollectionViewDelegateFlowLayout {
|
||||
return CGSize(width: width, height: 100)
|
||||
}
|
||||
}
|
||||
|
||||
final class MatrixFlowLayout : UICollectionViewFlowLayout {
|
||||
|
||||
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
|
||||
guard let layoutAttributesObjects = super.layoutAttributesForElements(in: rect) else { return nil }
|
||||
layoutAttributesObjects.forEach({ layoutAttributes in
|
||||
if layoutAttributes.representedElementCategory == .cell,
|
||||
let newFrame = layoutAttributesForItem(at: layoutAttributes.indexPath)?.frame {
|
||||
layoutAttributes.frame = newFrame
|
||||
}
|
||||
})
|
||||
return layoutAttributesObjects
|
||||
}
|
||||
|
||||
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
||||
guard let collectionView = collectionView,
|
||||
let layoutAttributes = super.layoutAttributesForItem(at: indexPath) else { return nil }
|
||||
let itemsCount = CGFloat(collectionView.numberOfItems(inSection: indexPath.section))
|
||||
layoutAttributes.frame.size.width = ceil(collectionView.safeAreaLayoutGuide.layoutFrame.width / itemsCount)
|
||||
return layoutAttributes
|
||||
}
|
||||
}
|
||||
|
||||
30
VDS/Components/Table/TableFlowLayout.swift
Normal file
30
VDS/Components/Table/TableFlowLayout.swift
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// TableFlowLayout.swift
|
||||
// VDS
|
||||
//
|
||||
// Created by Nadigadda, Sumanth on 02/05/24.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
final class MatrixFlowLayout : UICollectionViewFlowLayout {
|
||||
|
||||
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
|
||||
guard let layoutAttributesObjects = super.layoutAttributesForElements(in: rect) else { return nil }
|
||||
layoutAttributesObjects.forEach({ layoutAttributes in
|
||||
if layoutAttributes.representedElementCategory == .cell,
|
||||
let newFrame = layoutAttributesForItem(at: layoutAttributes.indexPath)?.frame {
|
||||
layoutAttributes.frame = newFrame
|
||||
}
|
||||
})
|
||||
return layoutAttributesObjects
|
||||
}
|
||||
|
||||
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
||||
guard let collectionView = collectionView,
|
||||
let layoutAttributes = super.layoutAttributesForItem(at: indexPath) else { return nil }
|
||||
let itemsCount = CGFloat(collectionView.numberOfItems(inSection: indexPath.section))
|
||||
layoutAttributes.frame.size.width = ceil(collectionView.safeAreaLayoutGuide.layoutFrame.width / itemsCount)
|
||||
return layoutAttributes
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user