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

Fix `UIButton` prepare/recover and improve `.none` transition #527

Open p4checo opened 1 year ago

p4checo commented 1 year ago

Summary

The current RecoverableButtonViewState model only works for very simple buttons where just the title is defined. This means that on more complex scenarios buttons aren't properly "prepared" to enter skeleton mode and remain visible for a while until they are covered with the skeleton layer, where the remaining elements are already in skeleton mode (e.g. labels). Furthermore, when configuring styling on buttons they reorder subviews/sublayers so that the skeleton layer didn't always show on top.

Same thing is true if layer.borderColor is non-nil - the border can be seen for a while until the skeleton layer covers it.

Additionally, using SkeletonTransitionStyle.none would still allow animations to be performed if any change done in prepareViewForSkeleton triggers a layout pass. This is especially noticeable when pushing a screen in a navigation controller and enabling skeleton mode in viewDidLoad.

Changes

Demo

https://user-images.githubusercontent.com/1391324/202869650-e0f87962-f7a7-451e-b218-64d54b9cb86b.mov

https://user-images.githubusercontent.com/1391324/202869594-e5bc47c6-0687-4fcc-9c54-103919b6a1d4.mov

Requirements