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.62k stars 1.12k forks source link

UICollectionViewCompositionalLayout with orthogonal section breaks skeletonable chain #504

Open KirilSivokoz opened 2 years ago

KirilSivokoz commented 2 years ago

Description

Hey!

We are using your awesome lib with UICollectionView for quite a while and everything was just perfect before we decided to migrate to UICollectionViewCompositionalLayout. Specifically, we have one section that has orthogonalScrollingBehavior set to .continuous.

What type of issue is this? (place an x in one of the [ ])

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


Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

SkeletonView Environment:

SkeletonView version: 1.29.3 Xcode version: 13.4.1 Swift version: 5

Steps to reproduce:

Please replace this with the steps to reproduce the behavior.

  1. Use UICollectionView with UICollectionViewCompositionalLayout and orthogonalScrollingBehavior.
  2. Set isSkeletonable for collection view and section items to true.

Expected result:

Section with orthogonalScrollingBehavior is skeletoned.

Actual result:

Section with orthogonalScrollingBehavior is not skeletoned.

Attachments:

Investigation results: It seems that for orthogonalScrollingBehavior system wraps items in _UICollectionViewOrthogonalScrollerEmbeddedScrollView, which obviously is not reachable directly and breaks isSkeletonable chain.

Possible workaround: I came up with the workaround, that is probably a bit too hacky for a PR. So I decided to open the issue instead.

extension UIScrollView {
    var isOrthogonalScrollView: Bool {
        let isInCollectionView = superview as? UICollectionView != nil
        return isInCollectionView && subviews.contains { $0.isSkeletonable }
    }

    override public var isSkeletonable: Bool {
        get {
            super.isSkeletonable || isOrthogonalScrollView
        }
        set {
            super.isSkeletonable = newValue
        }
    }
}
jhpassion0621 commented 1 year ago

Hi @KirilSivokoz Your solution helped me a lot. By the way when your above changes can be merged and released?

ardavydov commented 1 year ago

Confirm. Your solution also works for me