Juanpe / SkeletonView

☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
MIT License
12.59k stars 1.11k forks source link

Fallback to non-skeleton Header #416

Closed guidev closed 3 years ago

guidev commented 3 years ago

Summary

Sometimes a collectionview's header doesn't need to be 'skeletoned' since it's already ready to be displayed, while the content needs more time to load.

When collectionSkeletonView(_ skeletonView: UICollectionView, supplementaryViewIdentifierOfKind: String, at indexPath: IndexPath) -> ReusableCellIdentifier? returns nil, it's best if we fallback to the non-skeleton, original header.

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

Juanpe commented 3 years ago

Hi @guidev!

If I understand well, your point is to show the original header when the collection is "skeletoned", isn't it? If so, your code doesn't do that, I mean, the library tries to get the identifier for the header/footer and if it's not defined by the developer, the library will obtain the view from the original data source, then, the view will be "skeletonized".

So, there were some ways to do it:

  1. Set isSkeletonable to false, then the library will get the view but it won't do anything.
  2. Create a new method to prepare the header/footer for the skeleton. Like the library does with the cells: func collectionSkeletonView(_ skeletonView: UICollectionView, prepareCellForSkeleton cell: UICollectionViewCell, at indexPath: IndexPath). Using this new method you can set isSkeletonable to false in runtime for whatever header/footer you want.

BTW. I found an error if your collection has headers or footers and you don't implement the method func collectionSkeletonView(_ skeletonView: UICollectionView, supplementaryViewIdentifierOfKind: String, at indexPath: IndexPath) -> ReusableCellIdentifier?, the app crashes. With your code, if the identifier is not defined, the view will be provided by the original data source. So, we could merge it to solve this corner case. WDYT?

Thanks 🤙

Juanpe commented 3 years ago

Hi @guidev, could you check the message? I'd like to include the fix asap and if you don't want to do it, no problem, I'll do it :)

Please, let me know 👍🏼

Thanks

guidev commented 3 years ago

sounds good

Juanpe commented 3 years ago

Congratulations! 🎉 This was released as part of SkeletonView 1.21.0 🚀