-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow For collectionSkeletonView(_:numberOfRowsInSection:) to Return EstimatedNumberOfRows #400
Comments
Hi @rlziii! I don't exactly know what do you mean... 🤔 Now, you can define the number of rows that table will show when the skeleton is active by the data source method: func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
1
} Instead, if you don't implement this method, the library will calculate the estimated number of rows: This is what you want to do? |
What you described is correct. However, I was previously using a custom abstraction around func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int? {
skeletonConfiguration?.rowCounts[section]
} If the above resulted in a non-nil valve, then I would like that value to be used like it is today. If the above resulted in a |
Ok, I follow you now. 👍🏼 Yep, good point, and this could be very useful and would make more flexible the library. However, I'm not sure if modifying the signature is a good idea. 🤔 Another possibility could be to create a special case to define that the number of rows is indeterminate. Something like this: Then, the code would like this: func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int? {
skeletonConfiguration?.rowCounts[section] ?? SkeletonCollectionView.automaticNumberOfRows
} WDYT? could be a good solution to this issue? |
That would absolutely work. 👍 In the Objective-C days that was a common solution, or returning something like |
Cool, would you like to contribute to the project? It would be great :) |
Will do. 👍 |
Describe the feature or problem you’d like to solve
Currently if a class conforming to
SkeletonTableViewDataSource
implementscollectionSkeletonView(_:numberOfRowsInSection:)
, there is no way to fall back on the default implementation (which returnsskeletonView.estimatedNumberOfRows
) sinceestimatedNumberOfRows
hasinternal
protection level. This makes it difficult for wrappers that implementSkeletonTableViewDataSource
to allow for conditional conformance ofcollectionSkeletonView(_:numberOfRowsInSection:)
to return a possible (i.e. "overriding") value since the return type isInt
.Proposed solution
Change the return type of
collectionSkeletonView(_:numberOfRowsInSection:)
fromInt
toInt?
where returningnil
will then cause the default implementation to fallback to returningskeletonView.estimatedNumberOfRows
like usual. This will make the full protocol function signature:func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int?
This would allow for something like the following:
The text was updated successfully, but these errors were encountered: