Monday, October 23, 2023
HomeiOS Developmentios - A number of calls to scrollToItem(at:at:animated:) in fast succession causes...

ios – A number of calls to scrollToItem(at:at:animated:) in fast succession causes scrolling glitch in UICollectionView


In my setup I’ve a horizontal assortment view with chip type, on preliminary load the primary chip is chosen by default and akin to the chip an API name is made and it is information is loaded right into a vertical UICollectionView proper beneath.

On tapping any of the chips within the UICollectionView an API name is initiated and the chosen cell is scrolled into the centre of collectionview utilizing scrollToItem(at: selectedChipIndexPath, at: .centerHorizontally , animated: true). Plus I’ve to reload the the final chosen & present chosen indexPath to point that new cell is chosen.

The whole lot works effective if consumer faucets on the chips, seems to be on the beneath loaded information after which faucets on the subsequent chip.

But when the consumer faucets on consecutive chips rapidly then scrollToItem(at: selectedChipIndexPath, at: .centerHorizontally , animated: true) glitches the scroll animation some instances inflicting an disagreeable UX expertise.

Right here is my code:

collectionView.reloadItems(at: [lastSelectedIndexPath, selectedChipIndexPath])

// API Name
viewModel.fetchProductData(forPositon: selectedChipIndexPath)

DispatchQueue.primary. asyncAfter ( .now() + .seconds(0.4)) {
   scrollToItem(at: selectedChipIndexPath, at: .centerHorizontally , animated: true)
}

If I do not delay the scrolling by few milliseconds then scroll animation of assortment view begins to glitch very badly.

So can anybody level me in the correct course on how can I deal with or queue up a number of scrollToItem(at:at:animated:) calls in order that my collectionView scroll animation does not glitch.

I did attempt to wrap scrollToItem(at:at:animated:) in batch updates nevertheless it did not work.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments