Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SkeletonCollectionDataSource.automaticNumberOfRows with UITableView.automaticNumberOfSkeletonRows and UICollectionView.automaticNumberOfSkeletonItems #409

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection s

> 📣 **IMPORTANT!**
>
> If you return `SkeletonCollectionDataSource.automaticNumberOfRows` in the above method, it acts like the default behavior (i.e. it calculates how many cells needed to populate the whole tableview).
> If you return `UITableView.automaticNumberOfSkeletonRows` in the above method, it acts like the default behavior (i.e. it calculates how many cells needed to populate the whole tableview).

There is only one method you need to implement to let Skeleton know the cell identifier. This method doesn't have default implementation:
``` swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public protocol SkeletonCollectionViewDataSource: UICollectionViewDataSource {

public extension SkeletonCollectionViewDataSource {
func collectionSkeletonView(_ skeletonView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return SkeletonCollectionDataSource.automaticNumberOfRows
return UICollectionView.automaticNumberOfSkeletonItems
}

func collectionSkeletonView(_ skeletonView: UICollectionView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import UIKit

extension UICollectionView: CollectionSkeleton {
public static let automaticNumberOfSkeletonItems = -1

var estimatedNumberOfRows: Int {
guard let flowlayout = collectionViewLayout as? UICollectionViewFlowLayout else { return 0 }
switch flowlayout.scrollDirection {
Expand Down
6 changes: 2 additions & 4 deletions Sources/Collections/SkeletonCollectionDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import UIKit
public typealias ReusableCellIdentifier = String

class SkeletonCollectionDataSource: NSObject {
static let automaticNumberOfRows = -1

weak var originalTableViewDataSource: SkeletonTableViewDataSource?
weak var originalCollectionViewDataSource: SkeletonCollectionViewDataSource?
var rowHeight: CGFloat = 0.0
Expand Down Expand Up @@ -40,7 +38,7 @@ extension SkeletonCollectionDataSource: UITableViewDataSource {

let numberOfRows = originalTableViewDataSource.collectionSkeletonView(tableView, numberOfRowsInSection: section)

if numberOfRows == Self.automaticNumberOfRows {
if numberOfRows == UITableView.automaticNumberOfSkeletonRows {
return tableView.estimatedNumberOfRows
} else {
return numberOfRows
Expand Down Expand Up @@ -68,7 +66,7 @@ extension SkeletonCollectionDataSource: UICollectionViewDataSource {

let numberOfItems = originalCollectionViewDataSource.collectionSkeletonView(collectionView, numberOfItemsInSection: section)

if numberOfItems == Self.automaticNumberOfRows {
if numberOfItems == UICollectionView.automaticNumberOfSkeletonItems {
return collectionView.estimatedNumberOfRows
} else {
return numberOfItems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol SkeletonTableViewDataSource: UITableViewDataSource {

public extension SkeletonTableViewDataSource {
func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
return SkeletonCollectionDataSource.automaticNumberOfRows
return UITableView.automaticNumberOfSkeletonRows
}

func numSections(in collectionSkeletonView: UITableView) -> Int { return 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import UIKit
public typealias ReusableHeaderFooterIdentifier = String

extension UITableView: CollectionSkeleton {
public static let automaticNumberOfSkeletonRows = -1

var estimatedNumberOfRows: Int {
return Int(ceil(frame.height / rowHeight))
}
Expand Down