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.53k stars 1.1k forks source link

Issue with UiCollectionView contentOffset when showing/hiding skeletonView #398

Closed az0r234 closed 3 years ago

az0r234 commented 3 years ago

Description

Describe your issue here.

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.16.0 Xcode version: Version 12.5 (12E262) **Swift version: 5.0

Steps to reproduce:

Please replace this with the steps to reproduce the behavior.

  1. Create a UICollectionView with a layout of UICollectionViewFlowLayout ( vertical )
  2. Set the skeletonable properties in a UICollectionViewCell
  3. Set the contentOffset to (top: 180, left: 25, bottom: 80, right: 20)
  4. Use showSkeleton, and then Hideskeleton after making/mocking a network request

Expected result:

Please replace this with what you expected to happen. It was supposed to just stay in place and show the skeleton animation.

Actual result:

Please replace this with of what happened instead.
However, I'm getting a weird result. The collectionView is shifted upwards by about 30-40 points, and then once skeleton is stopped it moves back to the intended position. It's as if skeletonView is overriding the contentOffset value that I originally set.

Attachments:

Logs, screenshots, sample project, funny gif, etc.

https://user-images.githubusercontent.com/20172446/120860752-2eeada00-c554-11eb-9c0d-9f640f198207.mp4

harrisonsj commented 3 years ago

I couldn't reproduce the problem with a CollectionView (I think you mean contentInset when you say contentOffset), but I recently had the same problem with a TableView and fixed it by setting isScrollEnabled = true on the TableView immediately after calling the showSkeleton method.

az0r234 commented 3 years ago

@harrisonsj, I actually tried that, and yes I did mean contentInset. However, it doesn't seem to work with UICollectionView. It's a really annoying bug, but the temporary solution right now for me is to change the contentInset manually.

az0r234 commented 3 years ago

I figured out a better solution. I believe every-time that the showSkeleton method is being called, it readjusts the contentInset for UICollectionView, and with that also readjusts the content area of the scrollview. To fix it, what I did was set the contentAdjustmentBehavior for collectionView to .never: collectionView.contentAdjustmentBehavior = .never