SkeletonView icon indicating copy to clipboard operation
SkeletonView copied to clipboard

Rely on original delegate for section row, delegate, and footer heights

Open maadlog opened this issue 4 years ago • 6 comments

Summary

This PR attempts to provide the functionality required on issue #424 here

The approach was to delegate on the original table view delegate's implementation of the heightForXXX and estimatedHeightForXXX family of methods. The main issue faced is that given that those methods are optionals on the Objc protocol, then the return types aren't optional.

I was about to return UITableView.automaticDimension, which works similarly, but reading this piece of doc, it states that the value returned by heightForRow takes precedence over the property rowHeight. Following that logic, and to avoid breaking any current implementations, i delegated on the tableView's XXXheight and estimatedXXXHeight and properties, which i'm assuming (and please correct me if i'm wrong) are either properly set by users to the expected height or automaticDimension

Videos

https://user-images.githubusercontent.com/7192842/136675547-b8b79f25-7854-4b77-823e-678bb21e2df7.mp4

https://user-images.githubusercontent.com/7192842/136675549-9915e296-646d-4b7a-9abc-711da4961f4c.mp4

Steps to reproduce

Added on the iOS example: ViewController > SkeletonTableViewDelegate

    func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

    func numSections(in collectionSkeletonView: UITableView) -> Int {
        return 2
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }

And to test the different heights you can use any set of hardcoded values, including automaticDimension

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if (indexPath.section == 0) {
            return UITableView.automaticDimension
        } else {
            return 250
        }
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if (section == 0) {
            return 10
        } else {
            return 50
        }
    }

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if (section == 0) {
            return 10
        } else {
            return 50
        }
    }

Requirements (place an x in each of the [ ])

maadlog avatar Oct 09 '21 22:10 maadlog

Hi, @maadlog 👋🏼 thanks for this PR!

I've got a doubt about if this code works fine when the library calculates the number of rows. For example, in this line SkeletonCollectionDataSource.swift:42, we calculate the number of rows based on the height. But we are not considering that the sections or the cells could have different heights.

A possible solution could be using only this code when the developer defines the number of rows. WDYT?

Juanpe avatar Nov 04 '21 06:11 Juanpe

Hi @Juanpe ! Sounds good! I'll give it a spin and submit again!

maadlog avatar Nov 24 '21 16:11 maadlog

Hi @maadlog! Let me know if you need help to finish this feature :)

Juanpe avatar Dec 19 '21 15:12 Juanpe

@maadlog, Any updates on that? Don't worry if you don't have the bandwidth to do it. Let me know, and I could continue the development 😉

Juanpe avatar Jan 11 '22 12:01 Juanpe

Hi @Juanpe ! Sorry about the late response, i got swamped with the start of the year and didn't get any bandwidth to continue. Feel free to continue the development and thanks for the patience!

maadlog avatar Mar 22 '22 22:03 maadlog

@maadlog Any updates on this? This may be very useful

Eke avatar Jan 09 '23 07:01 Eke