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

.hideSkeleton() function does not work with UICollectionViewCompositionalLayout's Orthogonal Section Scrolling #546

Open dbpradana opened 1 year ago

dbpradana commented 1 year ago

Description

The skeletonView won't hide when the .hideSkeleton() function runs for a UICollectionView that has orthogonal scrolling behavior set at the Compositional Layout.

Code snippets and some more explanation are provided at the Attachment section below.

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.30.4 Xcode version: 14.3 (14E222b) Swift version: Swift 5

Steps to reproduce:

  1. Setup UICollectionView with UICollectionViewCompositionalLayout and orthogonalScrollingBehavior.
  2. Set isSkeletonable for collection view and it's cells to true.
  3. Run collectionView.showAnimatedGradientSkeleton().
  4. Run collectionView.hideSkeleton(reloadDataAfter: true, transition: .crossDissolve(0.25)) when data load is finished.

Expected result:

Animated skeleton hides

Actual result:

Animated skeleton are still showing

Attachments:

Here's the code when i set the UICollectionView's Compositional Layout: I've tried to comment out the section.orthogonalScrollingBehavior = .continuous part and the animated skeleton views are hides as expected when the .hideSkeleton() function runs.

// Set the UICollectionView
    private func setupCollectionView() {
        collectionView.delegate             = self
        collectionView.dataSource           = self
        collectionView.alwaysBounceVertical = false
        collectionView.collectionViewLayout = setCollectionCompositionalLayout()
        collectionView.register(SliderCell.self, forCellWithReuseIdentifier: "SliderCell")

        collectionView.showAnimatedGradientSkeleton()
    }

// Creates UICollectionView Compositional Layout
    private func setCollectionCompositionalLayout() -> UICollectionViewLayout {
        let item_size = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
        let item      = NSCollectionLayoutItem(layoutSize: item_size)

        let group_size = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
        let group      = NSCollectionLayoutGroup.horizontal(layoutSize: group_size, subitems: [item])

        let section = NSCollectionLayoutSection(group: group)
        section.orthogonalScrollingBehavior = .continuous
        return UICollectionViewCompositionalLayout(section: section)
    }
noorbhatia commented 1 year ago

@dbpradana I am facing the same issue, did you find any workaround?

noorbhatia commented 1 year ago

@Juanpe pls help

WangGouHei commented 1 year ago

same issue

dbpradana commented 1 year ago

@noorbhatia i don't really know if this workaround is affecting any performance or not, but right now the only way i could make it works is by modifying the function to set up the collectionView layout at my above code to setCollectionCompositionalLayout(shouldUseOrthogonalScroll: Bool).

Basically i need to first create a compositional layout without the orthogonal scrolling, do the data load, and after i run the .hideSkeleton() function, i run the setCollectionCompositionalLayout() function again but this time i set the shouldUseOrthogonalScroll to true, resetting the collectionView's layout and run collectionView.reloadData()

Mohamedgamal423 commented 12 months ago

just type cellname.hideSkeleton() in (cell for row at ) before configure cell with data