Skip to content

Commit b82efbc

Browse files
committed
Add deprecated message for warning
1 parent 037a932 commit b82efbc

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

InfiniteCollectionView/InfiniteCollectionView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ open class InfiniteCollectionView: UICollectionView {
3535
fileprivate var indexOffset: Int = 0
3636
fileprivate var contentWidth: CGFloat = UIScreen.main.bounds.width
3737
fileprivate var pageIndex = 0
38+
@available(*, deprecated, message: "It becomes unnecessary because it uses UICollectionViewFlowLayout.")
39+
open var cellWidth: CGFloat?
3840
required public init?(coder aDecoder: NSCoder) {
3941
super.init(coder: aDecoder)
4042
configure()
@@ -52,19 +54,19 @@ open class InfiniteCollectionView: UICollectionView {
5254
}
5355
open func rotate(_ notification: Notification) {
5456
contentWidth = totalContentWidth
55-
contentOffset = CGPoint(x: CGFloat(pageIndex + indexOffset) * cellWidth, y: contentOffset.y)
57+
contentOffset = CGPoint(x: CGFloat(pageIndex + indexOffset) * itemWidth, y: contentOffset.y)
5658
}
5759
}
5860

5961
// MARK: - private
6062
private extension InfiniteCollectionView {
61-
var cellWidth: CGFloat {
63+
var itemWidth: CGFloat {
6264
guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else { return 0 }
6365
return layout.itemSize.width + layout.minimumInteritemSpacing
6466
}
6567
var totalContentWidth: CGFloat {
6668
let numberOfCells: CGFloat = CGFloat(infiniteDataSource?.number(ofItems: self) ?? 0)
67-
return numberOfCells * cellWidth
69+
return numberOfCells * itemWidth
6870
}
6971
func configure() {
7072
delegate = self
@@ -77,9 +79,9 @@ private extension InfiniteCollectionView {
7779
let centerX = (scrollView.contentSize.width - bounds.width) / 2
7880
let distFromCenter = centerX - currentOffset.x
7981
if fabs(distFromCenter) > (contentWidth / 4) {
80-
let cellcount = distFromCenter / cellWidth
82+
let cellcount = distFromCenter / itemWidth
8183
let shiftCells = Int((cellcount > 0) ? floor(cellcount) : ceil(cellcount))
82-
let offsetCorrection = (abs(cellcount).truncatingRemainder(dividingBy: 1)) * cellWidth
84+
let offsetCorrection = (abs(cellcount).truncatingRemainder(dividingBy: 1)) * itemWidth
8385
if centerX > contentOffset.x {
8486
contentOffset = CGPoint(x: centerX - offsetCorrection, y: currentOffset.y)
8587
} else {

InfiniteCollectionView/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.1.0</string>
18+
<string>1.2.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)