Skeletonview: Support of iOS 13 DiffableDataSource

Created on 27 Mar 2020  路  6Comments  路  Source: Juanpe/SkeletonView

Hi

Do you plan to support iOS 13 new UICollectionViewDiffableDataSource ?

Thanks

help wanted 馃挕 enhancement

Most helpful comment

Exactly, you need to inherit from UITableViewDiffableDataSource and conforms to SkeletonTableViewDataSource. In my case I was using a tableview, but I think it will be the same for a collection view.

class MyDataSource: UITableViewDiffableDataSource<Int, Model> {

    init(tableView: UITableView) {
        super.init(tableView: tableView) { tableView, indexPath, model in
           // ...
        }
    }

}

// MARK: - SkeletonCollectionViewDataSource

extension MyDataSource: SkeletonTableViewDataSource {

    func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
        "ReusableIdentifier"
    }

}

Doing this will make skeleton working but as said before when hiding the skeleton you will need to set reloadDataAfter to false, otherwise the skeleton won't be hidden:

if showSkeleton {
   tableView.showAnimatedSkeleton()
} else {
   tableView.hideSkeleton(reloadDataAfter: false)
}

All 6 comments

I am also very curious if support for this is coming.

It's strange that there has not been any answer on the issue since March.
@Juanpe, could you, please, response

@Juanpe hello ?! Please response on this issue

SkeletonView is currently working with DiffableDataSource when setting false to reloadDataAfter when hiding skeleton view. I did nothing special beside that in order to have a working skeleton tableview

@tbaranes Hi! What do you mean by "is currently working"? As far as I know, you need to implement SkeletonCollectionViewDataSource to make it work with UICollectionView

Exactly, you need to inherit from UITableViewDiffableDataSource and conforms to SkeletonTableViewDataSource. In my case I was using a tableview, but I think it will be the same for a collection view.

class MyDataSource: UITableViewDiffableDataSource<Int, Model> {

    init(tableView: UITableView) {
        super.init(tableView: tableView) { tableView, indexPath, model in
           // ...
        }
    }

}

// MARK: - SkeletonCollectionViewDataSource

extension MyDataSource: SkeletonTableViewDataSource {

    func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
        "ReusableIdentifier"
    }

}

Doing this will make skeleton working but as said before when hiding the skeleton you will need to set reloadDataAfter to false, otherwise the skeleton won't be hidden:

if showSkeleton {
   tableView.showAnimatedSkeleton()
} else {
   tableView.hideSkeleton(reloadDataAfter: false)
}
Was this page helpful?
0 / 5 - 0 ratings